Express Flashcards
How do you addexpressto your package dependencies?
npm install express
What Express application method starts the server and binds it to a networkPORT?
app.listen([port[, host[, backlog]]][, callback])
How do you mount a middleware with an Express application?
Use Method
const app = express();
app.use((req, res, next) => {
console.log(‘Time:’, Date.now());
next();
});
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
Request object: a data model of the HTTP request message (FROM the Client!)
Response object: a data model of the HTTP response message (TO the Client!)
What is the appropriateContent-Typeheader for HTTP messages that contain JSON in their bodies?
application/json; charset=utf-8
What does theexpress.json()middleware do and when would you need it?
A built-in middle function in Express that parses incoming REQuests with JSON payloads and is based on body-parser
When the request is a JSON object
What is the significance of an HTTP request’s method?
A set of request methods to indicate the desired action to be performed for a given resource.
What doesexpress.static()return?
Function
What is the local__dirnamevariable in a Node.js module?
The directory name of the current module
What does thejoin()method of Node’spathmodule do?
Joins all given path segments together using the platform-specific separator as a delimiter, then normalizes the resulting path. The specified path segments must be strings, separated by commas.