Express Flashcards
How do you add express to your package dependencies?
const express = require('express') const app = express()
What Express application method binds the server to a network PORT?
app.listen
How do you register a middleware with an Express application?
app.use and pass in a function that takes (req, res, next) parameter
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
req, res, next
What is the Content-Type header of HTTP requests and responses used for?
How the recipient should handle the body content
What does express.static() return?
A middleware function that serves static 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?
Joins the file paths together that are listen as args
What is the appropriate Content-Type header for requests and responses that contain JSON in their bodies?
application/json
What does the express.json() middleware do and when would you need it?
express.json() is a method inbuilt in express to recognize the incoming Request Object as a JSON Object. This method is called as a middleware in your application using the code: app.use(express.json());
What is the significance of an HTTP request’s method?
So that YOU know what you are trying to do in a function (app.delete would imply that something needs to be deleted)