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?
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 object and response object.
What is middleware?
A series of 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. The next middleware function is commonly denoted by a variable named next.
What can middleware functions do?
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; charset=utf-8
What is the significance of an HTTP request’s method?
Helps specify intent of the client.
What does the express.json() middleware do and when would you need it?
Parses incoming requests with JSON payloads.
It’s needed when trying to parse incoming JSON data.
What does express.static() return?
A function.
What is the local __dirname variable in a Node.js module?
The directory name of the current 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, then normalizes the resulting path.
What do you pass as the argument for the .catch when handling synchronous and asynchronous errors?
err => next(err)
When handling several errors what can you do for organizational and higher level framework purposes?
Define different error-handling middleware functions.