1. Home
  2. Explore
  3. Computer Science
  4. Express.js REST API

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Express.js REST API

  • 45Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Project Setup
  • 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?

Tap to flipClick to flipspace

The mkdir command.

Or swipe the card

45 cards

  1. What command is used to create a new directory for an Express application?

    The mkdir command.

  2. What command opens a directory in VS Code from the terminal?

    code .

  3. What prerequisite is necessary to build a Node.js REST API with Express?

    Node.js must be installed.

  4. How do you initialize a new Node.js application in a directory?

    Run npm init -y.

  5. What file is created after initializing a Node.js application?

    The package.json file.

  6. How do you install the Express.js dependency?

    Run npm install express.

  7. What is a common filename for the main Express server file?

    index.js or main.js.

  8. How do you import the Express module into your JavaScript file?

    Use const express = require('express');

  9. How do you create a new Express application instance?

    const app = express();

  10. How do you make an Express app listen on a specific port?

    app.listen(port, callback);

  11. What command executes a Node.js application from the terminal?

    node index.js (assuming index.js is the main file).

  12. What tool allows for hot reloading of a Node.js application during development?

    Nodemon.

  13. How do you install Nodemon globally?

    npm install nodemon -g (or sudo npm install nodemon -g on Mac/Linux).

  14. How do you configure a 'dev' script in package.json to use Nodemon?

    Add 'dev': 'nodemon index.js' to the scripts section.

  15. What does a 'route' define in a REST API?

    A specific endpoint and the HTTP method (verb) that clients can access to perform operations.

  16. What HTTP verb is typically used to retrieve data?

    GET.

  17. What HTTP verb is typically used to add new data?

    POST.

  18. What HTTP verb is typically used to update existing data?

    PUT (or PATCH).

  19. What HTTP verb is typically used to delete data?

    DELETE.

  20. What are the two parameters passed to a route's callback function in Express?

    The request (req) object and the response (res) object.

  21. How do you send JSON data as a response in Express?

    res.json(data);

  22. What is Postman used for in API development?

    To simulate client requests and test API endpoints.

  23. Where is data typically passed for a POST request in Postman?

    In the request body, often as JSON.

  24. How does Express process JSON data sent in the request body?

    By using the express.json() middleware.

  25. How do you access data from the request body in an Express route handler?

    req.body.propertyName or by destructuring: const { propertyName } = req.body;

  26. What package is commonly used to generate unique IDs for records?

    The uuid package.

  27. How do you install the uuid package?

    npm install uuid.

  28. How do you import and use the v4 UUID generation function from uuid?

    const { v4: uuidv4 } = require('uuid'); and then call uuidv4() to generate an ID.

  29. 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.

  30. How do you access dynamic parameters from the URL in an Express route handler?

    Using req.params.parameterName or destructuring const { parameterName } = req.params;

  31. 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.

  32. How can you reorganize Express routes into separate files?

    By using express.Router() to create modular route handlers.

  33. How do you create an express.Router() instance?

    const router = require('express').Router();

  34. How do you export a router from a modular route file?

    module.exports = router;

  35. How do you mount a modular router into the main Express application?

    app.use('/basepath', require('./routes/your_router_file'));

  36. 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.

  37. What is 'middleware' in Express.js?

    Functions that have access to the request and response objects and the next function in the application's request-response cycle.

  38. When does middleware run in the request-response cycle?

    It runs before the request reaches the route handler.

  39. What is a common use case for middleware?

    Authentication and authorization checks.

  40. How do you define a custom middleware function in Express?

    It's a function that takes req, res, and next as parameters and potentially exports it.

  41. How do you access data from the request headers in Express?

    Using req.header('Header-Name').

  42. What function is used to pass control to the next middleware or route handler?

    next().

  43. What HTTP status code indicates a 'Forbidden' response?

  44. How do you set a specific HTTP status code for a response in Express?

    res.status(statusCode).json(data); (or .send(), etc.).

  45. 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.

Card 1 of 45
Card 1 of 45

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent