Podcast
Questions and Answers
What is the primary purpose of Git in software development?
What is the primary purpose of Git in software development?
- To track software changes and facilitate team collaboration. (correct)
- To convert code examples from GitHub into different languages.
- To automatically manage project documentation.
- To replace online repositories.
What command is used to check the installed version of Git?
What command is used to check the installed version of Git?
- `git show version`
- `git --version` (correct)
- `git check version`
- `git version`
What is the purpose of the command git clone
?
What is the purpose of the command git clone
?
- To copy a repository from a remote source to a local machine. (correct)
- To upload local changes to a remote repository.
- To update the existing Git installation.
- To create a new branch in an existing repository.
What security issue does CORS address when developing web applications?
What security issue does CORS address when developing web applications?
What is the main reason a browser might block a request using the file://
protocol?
What is the main reason a browser might block a request using the file://
protocol?
What is the primary function of the Live Server extension in VSCode?
What is the primary function of the Live Server extension in VSCode?
When using http-server
, what does the -p
flag specify?
When using http-server
, what does the -p
flag specify?
In the context of package.json
, what is the purpose of the scripts
object?
In the context of package.json
, what is the purpose of the scripts
object?
Why is it important to update the .gitignore
file to exclude node_modules
?
Why is it important to update the .gitignore
file to exclude node_modules
?
What is the purpose of the git config user.name
and git config user.email
commands?
What is the purpose of the git config user.name
and git config user.email
commands?
Flashcards
What is Git?
What is Git?
A free, open-source system used for tracking software changes and team collaboration.
What is CORS?
What is CORS?
A common web app issue where requests to different domains are restricted by browsers for security.
VSCode's Live Server Extension
VSCode's Live Server Extension
Quickly host local files for development using an extension for VSCode.
What is http-server?
What is http-server?
Signup and view all the flashcards
npm run
npm run
Signup and view all the flashcards
What is Express?
What is Express?
Signup and view all the flashcards
.gitignore
.gitignore
Signup and view all the flashcards
git config user
git config user
Signup and view all the flashcards
Git staging
Git staging
Signup and view all the flashcards
Git Commit vs Sync
Git Commit vs Sync
Signup and view all the flashcards
Study Notes
- Git is a free and open-source distributed version control system for tracking software in teams.
- Git (the command-line tool) is used to download code examples from GitHub.
Installing Git
- To install Git, go to the provided link.
- Open a terminal and check the version using
git --version
. - The MDN page on Modules has a repository with examples.
- Clone the repository using
git clone https://github.com/mdn/js-examples.git
. - Open the repository in VSCode with
code js-examples
. - "code" is the command-line command for VSCode;
code <path>
opens a file or folder.
File Structure
- The file structure includes:
modules
,canvas.js
,square.js
,index.html
, andmain.js
. - Open
index.html
to find a simple file referencingmain.js
. - Right-click
index.html
, select "Reveal in File Explorer," then double-click to open it in a browser.
CORS Error
- A white screen may appear, and the browser console will show an error message related to CORS.
- CORS (Cross-Origin Resource Sharing) is a common issue when web apps request resources from other domains.
- The
html
file is looking for a resource using thefile://
protocol, which modern browsers block for security. - The solution is to host the files using the
http://
protocol.
VSCode's Live Server Extension
- Install the Live Server extension from VSCode's marketplace to quickly host local files.
- After installing, reload if needed, then right-click
index.html
and select "Open with Live Server". - The browser should host the project on port 5500.
- The file can be accessed at
http://127.0.0.1:5500/js-examples/module-examples/basic-modules/index.html
. - Refreshing the page will display a blue square and a random-sized square with different colors.
HTTP-Server CLI
- HTTP-Server CLI can be used to quickly host a server.
- Run
npm install http-server
in the js-examples folder. - If you attempt to run
http-server
via the terminal it will return "http-server' is not recognized". - Instead of installing globally, use the
package.json
scripts property. - Open
package.json
and add thescripts
section. - The
index
command runshttp-server -p 9000
. npm run index
, openslocalhost:9000
.
Defining Custom Names
- Names that don't sound like a proper command can be defined.
- Cancel the current
http-server
with Ctrl+C, then runnpm run basic-modules-example
. - Now,
localhost:9000
will show the blue-square-random-square canvas. - Shows that you are running something defined under the scripts object in
package.json
. - Commands defined in
package.json
have access to installed packages. - Hosting serves a specific file/folder, with browsers defaulting to
index.html
.
Express Library
- Express is a minimalist web framework for Node.
- Run
npm install express
at js-examples. - Create
server.js
and add the provided example code from the express npm page. - Running
node server.js
and hittinglocalhost:3000
displays "Hello World". - Line 1 imports the library with
require
using CJS; Line 2 instantiates a server namedapp
. - Line 4 configures the
app
to listen to GET requests on path/
(IP:PORT). - The 2nd argument on line 4 is a callback function that is called whenever the server receives a GET request on
/
. - The callback function's first argument
req
has request information and the 2nd argumentres
is for the callback to respond. - Update
server.js
to hostindex.html
pages. - Stop the server, run it again, and it will display the blue-and-random-squares example.
- Fix the ESM error by updating
package.json
. - Instead of manually creating the response, the server hosts static files from
modules-examples/basic-modules
on the/
path. - A callback function is added to
app
slisten
to indicate the port the app is hosted on and to provide a clickable link. - Note: Issue with this implementation will be fixed in lab 3.
- Only works running from Root of js-examples folder.
Git Workflow
- Open the "Source Control" tab in VSCode.
- Add "node_modules" to
.gitignore
file. - Use Ctrl+P to search for ".gitignore".
- Committing changes saves them to the repository.
- Configure the following basics by running from terminal:
git config user.name FirstName LastName
andgit config user.email [email protected]
. - Confirm the values set by running commands without arguments.
- Using the + symbol on the files to stage the files and they'll move from "Changes" to "Staged Changes".
- Add a commit message and press Commit.
- After committing it will display "Sync Changes;" Do not press button because you do not have permission to upload changes to MDN's repository.
Lab Submissions
- Create
_your_name_lab2
file to show up at the top of the list without type or any content inside. - Adding new entry to scripts object in
package.json
to runhttp-server
on port 4000 with the command npm run your-name-lab2. - Take screenshot #1 of IDE with
package.json
, file list open, and terminal. - Take screenshot #2 of the hosted index.
- Update
server.js
to host foldermodule-examples/basic-modules
, set path to your name folder on port 5000. - Take screenshot #3 with source code and terminal running
node server.js
. - Ensure there are no warnings about import compatibility.
- Take screenshot #4
localhost:5000/your-name-lab2
.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.