Express Flashcards
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?
A request object (req
)
A response object (res
)
A next object (next
)
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’s used to parse incoming requests with a JSON body and assign the parsed data to req.body
and one would need it when passing JSON objects to the server for some form of processing
What does express.static() return?
It returns a middleware function that serves static files.
What is the local __dirname variable in a Node.js module?
It is a local variable that returns the directory name of the current module. It returns the folder path of the current JavaScript file.
What does the join() method of Node’s path module do?
It joins together path
segments together, normalizes them, and then returns the resulting path.