Express Flashcards
How do you add express to your package dependencies?
use the command npm install express.
but first make sure you created a new package.json using the npm init command.
What Express application method starts the server and binds it to a network PORT?
app.listen method binds and listens for connections on the specified host and port.
How do you mount a middleware with an Express application?
app.use(method) - Mounts the specified middleware function or functions at the specified path: the middleware function is executed when the base of the requested path matches path.
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
Request Object (req) and Response Object (res)
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?
express.json( ) parses incoming JSON requests and puts the parsed data in req.body.
What is the significance of an HTTP request’s method?
indicate the desired action to be performed for a given resource.
What does express.static() return?
returns a function
static files such as images, CSS files, and JavaScript files.
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?
join all given path-segments using the platform-specific delimiter to form a single path.