Express JS 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(port, callback)
How do you mount a middleware with an Express application?
Using the app.use(callback) method
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
req(request) and res(response)
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 parses implicit key-value pairs in an HTTP request into a JSON, and assigns it to req.body; it is necessary when the client sends a JSON
What is the significance of an HTTP request’s method?
It is used semantically for deciding the proper middleware function to use
What does express.static() return?
A middleware function that adds a specified directory from which to serve files
What is the local __dirname variable in a Node.js module?
It is a string of the absolute path to the directory containing the module
What does the join() method of Node’s path module do?
It takes strings of paths, and returns a composite of the paths