Express Flashcards
How do you add express to your package dependencies?
Npm innit -yes then npm install express
What Express application method starts the server and binds it to a network PORT?
Listen method
app.listen(3000, () => {
console.log(‘Express server listening on port 3000’);
});
How do you mount a middleware with an Express application?
Pass it a callback function that has parameters response and next. Call use to install middleware
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
Req (request) and res (response) and next
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?
indicate the desired action to be performed for a given resource
What does the express.json() middleware do and when would you need it?
Method to recognize the incoming Request Object as a JSON Object
What does express.static() return?
Returns a middleware that serves static files
What is the local __dirname variable in a Node.js module?
directory name of the current module
What does the join() method of Node’s path module do?
joins the specified path segments into one path