express.js Flashcards
How do you add express to your package dependencies?
npm install express –save
What Express application method starts the server and binds it to a network PORT?
app.listen([port[, host[, backlog]]][, callback])
How do you mount a middleware with an Express application?
app.use([path,] callback [, callback…])
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
request and response object
What is a middleware function?
Middleware functions are 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 tasks can a middleware function perform?
-Execute any code.
-Make changes to the request and the response objects.
-End the request-response cycle.
-Call the next middleware function in the stack.
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 JSON requests and puts the parsed data in req.body.
Need it when we want to accept JSON.
What does express.static() return?
serveStatic function
What is the local __dirname variable in a Node.js module?
absolute path to the current module
What does the join() method of Node’s path module do?
combines multiple strings into a directory path format