Express.js REST API
- 45Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
- spaceFlip card
- KI knew it
- DI didn't know it
- ←Previous card
- →Next card
What command is used to create a new directory for an Express application?
The mkdir command.
Or swipe the card
45 cards
What command is used to create a new directory for an Express application?
The
mkdircommand.What command opens a directory in VS Code from the terminal?
code .What prerequisite is necessary to build a Node.js REST API with Express?
Node.js must be installed.
How do you initialize a new Node.js application in a directory?
Run
npm init -y.What file is created after initializing a Node.js application?
The
package.jsonfile.How do you install the Express.js dependency?
Run
npm install express.What is a common filename for the main Express server file?
index.jsormain.js.How do you import the Express module into your JavaScript file?
Use
const express = require('express');How do you create a new Express application instance?
const app = express();How do you make an Express app listen on a specific port?
app.listen(port, callback);What command executes a Node.js application from the terminal?
node index.js(assumingindex.jsis the main file).What tool allows for hot reloading of a Node.js application during development?
Nodemon.
How do you install Nodemon globally?
npm install nodemon -g(orsudo npm install nodemon -gon Mac/Linux).How do you configure a 'dev' script in
package.jsonto use Nodemon?Add
'dev': 'nodemon index.js'to thescriptssection.What does a 'route' define in a REST API?
A specific endpoint and the HTTP method (verb) that clients can access to perform operations.
What HTTP verb is typically used to retrieve data?
GET.
What HTTP verb is typically used to add new data?
POST.
What HTTP verb is typically used to update existing data?
PUT (or PATCH).
What HTTP verb is typically used to delete data?
DELETE.
What are the two parameters passed to a route's callback function in Express?
The
request(req) object and theresponse(res) object.How do you send JSON data as a response in Express?
res.json(data);What is Postman used for in API development?
To simulate client requests and test API endpoints.
Where is data typically passed for a POST request in Postman?
In the request body, often as JSON.
How does Express process JSON data sent in the request body?
By using the
express.json()middleware.How do you access data from the request body in an Express route handler?
req.body.propertyNameor by destructuring:const { propertyName } = req.body;What package is commonly used to generate unique IDs for records?
The
uuidpackage.How do you install the
uuidpackage?npm install uuid.How do you import and use the v4 UUID generation function from
uuid?const { v4: uuidv4 } = require('uuid');and then calluuidv4()to generate an ID.How can you specify a dynamic parameter in an Express route path?
By using a colon followed by the parameter name, e.g.,
/todos/:id.How do you access dynamic parameters from the URL in an Express route handler?
Using
req.params.parameterNameor destructuringconst { parameterName } = req.params;Why does an in-memory array of to-dos reset when the server restarts?
Because the data is stored in a variable in the server's memory and is not persisted in a database.
How can you reorganize Express routes into separate files?
By using
express.Router()to create modular route handlers.How do you create an
express.Router()instance?const router = require('express').Router();How do you export a router from a modular route file?
module.exports = router;How do you mount a modular router into the main Express application?
app.use('/basepath', require('./routes/your_router_file'));What is the purpose of the base path string in
app.use('/todos', require('./routes/todos'));?It defines a common prefix for all routes within the mounted router.
What is 'middleware' in Express.js?
Functions that have access to the request and response objects and the
nextfunction in the application's request-response cycle.When does middleware run in the request-response cycle?
It runs before the request reaches the route handler.
What is a common use case for middleware?
Authentication and authorization checks.
How do you define a custom middleware function in Express?
It's a function that takes
req,res, andnextas parameters and potentially exports it.How do you access data from the request headers in Express?
Using
req.header('Header-Name').What function is used to pass control to the next middleware or route handler?
next().What HTTP status code indicates a 'Forbidden' response?
How do you set a specific HTTP status code for a response in Express?
res.status(statusCode).json(data);(or.send(), etc.).How do you apply a middleware function to a specific route handler?
Insert the middleware function between the path and the callback function in the route definition.

Ask anything
We've read this whole study set, so questions about it get the best answers.