npm / Express Flashcards
What is NPM?
software registry that developers use to borrow/share packages; can also refer to the npm website or the Command Line Interface (CLI)
What is a package?
reusable code - a directory w/ one or more files, including package.json
How can you create a package.json with npm?
navigate to the root directory of the package; npm init -y
What is a dependency and how do you add one to a package?
a package required by the application; npm install dependencyName
What happens when you add a dependency to a package with npm?
updates the package.json file to include the dependency and downloads the dependency library to the computer
How do you add express to your package dependencies?
npm install express
What Express application method starts the server and binds it to a network PORT?
listen( )
How do you mount a middleware with an Express application?
.use( ) method
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
request and response objects
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application/json
What is the significance of an HTTP request’s method?
for routing - determines how an application responds to a client request to a particular endpoint
What does the express.json( ) middleware do and when would you need it?
it parses JSON; you use it when your app needs to parse JSON request bodies (so that they are not undefined)
What does express.static() return?
middleware function that serves static files
What is the local __dirname variable in a Node.js module?
the absolute file path to the directory of the Node.js module
What does the join() method of Node’s path module do?
joins all given path segments together using the platform-specific separator as a delimiter