npm Flashcards
What is NPM?
software registry where open source developers can share and borrow packages
consists of website, command line interface (CLI), and the registry
What is a package?
a file or directory that is described by a package.json file that contains reusable code
How can you create a package.json with npm?
npm init –yes
What is a dependency and how to you add one to a package?
a dependency is a package that the project depends on
npm install
What happens when you add a dependency to a package with npm?
package gets installed in a folder called node-modules and package.json is updated
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?
app.listen(PORT, function)
How do you mount a middleware with an Express application?
call a middleware method like app.use()
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
req and res
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application/json
What does the express.json() middleware do and when would you need it?
it parses incoming requests in json, used when incoming requests have json bodies
What is the significance of an HTTP request’s method?
determines what action SHOULD be done with the given resource but programmer can make it do whatever
if empty code block, then httpie freezes for 30s
What does express.static() return?
a middleware function preprogrammed to look in a directory and serve files
What is the local __dirname variable in a Node.js module?
string of directory name of the current module (absolute path)
What does the join() method of Node’s path module do?
joins path names
path.join('/foo', 'bar', 'baz/asdf', 'quux', '..'); // Returns: '/foo/bar/baz/asdf'