express Flashcards
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?
const express = require('express'); const app = express(); app.listen(3000, () => { // eslint-disable-next-line no-console console.log('Express server listening on port 3000'); });
listen method
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?
req, res
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?
enable communications between clients and servers
What does the express.json() middleware do and when would you need it?
parses incoming JSON requests and puts the parsed data in req
What does express.static() return?
HTTP 404 if it can’t find a file, so that means you should typically call app.use(express. static()) after the rest of your app.
returns a function, and that functions returns file or the error message.
What is the local __dirname variable in a Node.js module?
an environment variable that tells you the absolute path of the directory containing the currently executing file
What does the join() method of Node’s path module do?
joins the specified path segments into one path
joins multiple segments of the file path.