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?
The .listen() method
How do you mount a middleware with an Express application?
The .use() method
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
The response, and requests
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
Content type: application/json for JSON
content type: text/html for text
What is the significance of an HTTP request’s method?
To define the action between the client and the server
What does the express.json() middleware do and when would you need it?
- It parses the request body
2. When the client is sending a JSON body and you care about it
What does express.static() return?
a middleware function
What is the local __dirname variable in a Node.js module?
an absolute path to the directory that the module is in starting from the root
What does the join() method of Node’s path module do?
it joins the paths given as arguments and assigns respective “/”
What is the practical utility of express.static() in the web development world?
so you don’t have to define get methods for every single file you want to display
What is the purpose of making a duplicate .env file from .env.example?
ENV = environment variables file
adds environmental objects as properties of process.env object when you require dotenv
What is the significance of using “next” as a parameter when defining a network request callback definition?
- to tell express to short circuit to error middleware
2. to tell the express framework to go to the next middleware
why did we previously have to use console.error(error) but now it’s appropriate to use throw ClientError?
because error middleware is installed