Express.js Flashcards
What is Express useful for?
Implementing HTTP endpoints. Helps manage routes.
How does Express fit into a full-stack web application?
Runs on top of node and manages the HTTP requests between front end and back end.
How do you add express to your package dependencies?
npm install command. “npm install express”
What Express application method starts the server and binds it to a network PORT?
app.listen()
What is Express middleware?
What is Express middleware useful for?
Carry out functions inbetween express and the http request.
How do you mount a middleware with an Express application?
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
The request object, the response object, and the next middleware function.
What is Express middleware useful for?
Carry out functions in-between express and the http request.
What is an API endpoint?
The path or URL for backend API plus its prefix, e.g. /api/grades. It makes it easier to determine which endpoints are intended for which types of request. With this information, Express code can more easily optimize each style of API for its intended use.
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application/json; charset-utf-8
What is the significance of an HTTP request’s method?
An HTTP request’s method indicates what action will be performed.
What does the express.json() middleware do and when would you need it?
Returns middleware that only parses JSON and only looks at requests where the Content-Type header matches the type option. You need it to parse JSON request bodies.
What does app.listen() do?
It puts something on the event queue that listens for network requests/traffic. When there is a request, it runs through the middleware and then puts the listener back on the event queue.
What is the purpose of the Express Static middleware?
To serve static files.