NPM/Express/Babel Flashcards
What is NPM?
Node package manager, software registry that makes it easy for JS developers to share reusable code to solve problems
- website, command line client, registry
What is a package?
directory with one or more files inside and package.json file
How can you create a package.json with npm?
npm init -y (for default) in current directory
What is a dependency and how do you add one to a package?
Any other packages that your package depends on
**npm install package-name
What happens when you add a dependency to a package with npm?
- the package name is added under “dependencies” in package.json
- npm will downloads listed dependencies under node-modules directory
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
How do you mount a middleware with an Express application?
app.use()
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 purpose of the Content-Type header in HTTP request and response messages?
In a response, the header tells the client what kind of file type the returned content is
In a request, the client tells the server what kind of information is being sent
What does express.static() return?
a middleware function that returns static files such as images, CSS files, and JavaScript files in the specified root directory
What is the local __dirname variable in a Node.js module?
full directory name of current module or absolute path
What does the join() method of Node’s path module do?
concatenates individual segments or strings together to form a file path
middleware functions (express)
functions that have access to the request object (req), the response object (res), and the next middleware function in the application’s request-response cycle
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application/json