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

  • 41Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Introduction to Express
The framework being used to build a REST API on top of Node.js in this crash course is called
.

41 questions

  1. 1
    The framework being used to build a REST API on top of Node.js in this crash course is called
    _____
    .
    Hint

    This is a popular web application framework for Node.js.

    Answer

    Express.js

  2. 2
    Before starting to build the Express.js application, it is expected that the user understands what a
    _____
    API is.
    Hint

    This type of API follows a set of architectural constraints for web services.

    Answer

    restful

  3. 3
    The first step in setting up the Express.js application is to create a
    _____
    where the application's files will reside.
    Hint

    This is a fundamental organizational unit in a file system.

    Answer

    directory

  4. 4
    The command npm init -y is used to initialize a Node application, which creates a
    _____
    file in the project directory.
    Hint

    This file manages project dependencies and scripts.

    Answer

    package.json

  5. 5
    To install the Express.js framework, the command `npm install
    _____
    ` is executed.
    Hint

    This is the primary dependency for building the REST API.

    Answer

    express

  6. 6
    The main file where the Express server logic will typically reside is named `
    _____
    ` by many developers.
    Hint

    This is a common convention for the entry point of a JavaScript application.

    Answer

    index.js

  7. 7
    To create an instance of an Express application, the express() function is
    _____
    .
    Hint

    This action creates the 'app' object that handles requests.

    Answer

    invoked

  8. 8
    The app.listen() method is used to start the server and
    _____
    for incoming requests on a specified port.
    Hint

    This method binds the application to a network address.

    Answer

    listen

  9. 9
    When the server starts successfully, a common practice is to use console.log() within the app.listen callback to confirm that the application is listening on port
    _____
    .
    Hint

    This is a frequently used default port for development servers.

    Answer

    3000

  10. 10
    To execute the Node.js application from the terminal, the command `node
    _____
    is used, assumingindex.js` is the main file.
    Hint

    This command directly runs a JavaScript file with Node.js.

    Answer

    index

  11. 11
    In Express, routes are defined using HTTP
    _____
    like get, post, put, patch, and delete.
    Hint

    These indicate the type of action to be performed on a resource.

    Answer

    verbs

  12. 12
    For retrieving data, it is considered best practice to use the `
    _____
    ` verb for defining a route.
    Hint

    This verb is idempotent and safe for fetching resources.

    Answer

    get

  13. 13
    The first parameter when defining an Express route handler is the
    _____
    of the route, such as /todos.
    Hint

    This specifies the URL endpoint that the route will handle.

    Answer

    path

  14. 14
    A route handler callback function typically takes two parameters: `
    _____
    for the incoming request andres` for the outgoing response.
    Hint

    These are shorthand for request and response objects.

    Answer

    req

  15. 15
    To send back JSON data in an Express route, the `res.
    _____
    ()method is commonly used instead ofres.send()`.
    Hint

    This method automatically sets the Content-Type header to application/json.

    Answer

    json

  16. 16
    To enable hot reloading for a Node application during development, the nodemon package can be installed
    _____
    using npm install nodemon -g.
    Hint

    This installation type makes the package available across all projects.

    Answer

    globally

  17. 17
    A dev script can be added to the `
    _____
    file, utilizingnodemon index.js` to run the application with hot reload functionality.
    Hint

    This file contains scripts that can be run with npm run.

    Answer

    package.json

  18. 18
    GET requests can be tested directly in the browser by navigating to the appropriate
    _____
    .
    Hint

    Browsers perform GET requests by default when you type an address.

    Answer

    URL

  19. 19
    Postman is a popular tool used to
    _____
    a client making various types of HTTP requests, including GET, POST, PUT, and DELETE.
    Hint

    This tool helps developers test API endpoints by acting like a browser or mobile app.

    Answer

    simulate

  20. 20
    To add data to the server, the `
    _____
    ` HTTP verb is typically used for routes.
    Hint

    This verb is used to submit an entity to the specified resource, often causing a change in state or a side effect.

    Answer

    post

  21. 21
    When sending data with a POST request, the data is usually passed within the request
    _____
    .
    Hint

    This is where the actual payload of the request resides.

    Answer

    body

  22. 22
    To process JSON data sent in the request body, Express needs to be configured with a
    _____
    using app.use(express.json()).
    Hint

    This function processes requests before they reach the route handler.

    Answer

    middleware

  23. 23
    The express.json() middleware allows the application to
    _____
    the JSON data from the request body.
    Hint

    This action converts the JSON string into a JavaScript object.

    Answer

    parse

  24. 24
    When creating a new to-do item, its title is typically destructured from `req.body.
    _____
    `.
    Hint

    This specific property holds the name of the to-do item.

    Answer

    title

  25. 25
    To generate unique string IDs for records, the `
    _____
    ` package can be installed.
    Hint

    This package helps create Universally Unique Identifiers.

    Answer

    uuid

  26. 26
    The v4 function from the uuid package is invoked to create a brand new random
    _____
    for a to-do item.
    Hint

    This is the data type of the unique identifier generated.

    Answer

    string

  27. 27
    When fetching a specific to-do, the unique identifier (ID) is typically passed as a
    _____
    parameter in the route, e.g., /todos/:id.
    Hint

    This part of the URL changes based on the specific resource being requested.

    Answer

    dynamic

  28. 28
    In Express, a dynamic route parameter like :id can be accessed from `req.
    _____
    `.
    Hint

    This object contains route parameters (e.g., from /users/:id).

    Answer

    params

  29. 29
    To modify an existing resource, the `
    _____
    ` HTTP verb is commonly used.
    Hint

    This verb is typically used for replacing a resource or updating its properties.

    Answer

    put

  30. 30
    For updating the completed status of a to-do item, the `
    _____
    method can be used on thetodos` array to find the index of the specific element.
    Hint

    This array method returns the index of the first element in the array that satisfies the provided testing function.

    Answer

    findIndex

  31. 31
    To remove a resource from the server, the `
    _____
    ` HTTP verb is utilized.
    Hint

    This verb indicates that the specified resource should be removed.

    Answer

    delete

  32. 32
    When deleting a to-do, the `
    _____
    ` array method can be used to create a new array containing all elements except the one to be deleted.
    Hint

    This method creates a new array with all elements that pass the test implemented by the provided function.

    Answer

    filter

  33. 33
    To organize routes and avoid having all route handlers in one file, they can be grouped into separate files within a `
    _____
    ` directory.
    Hint

    This directory name suggests its purpose: storing definitions for application endpoints.

    Answer

    routes

  34. 34
    Instead of app, inside a dedicated route file, an express.Router() instance is used to define
    _____
    .
    Hint

    This module provides a way to create modular, mountable route handlers.

    Answer

    router

  35. 35
    After defining routes in a separate file using router, the `
    _____
    object is used to export therouter` instance so it can be imported elsewhere.
    Hint

    This is a Node.js specific object used for exporting values from a module.

    Answer

    module.exports

  36. 36
    In the main index.js file, app.use() is used to
    _____
    the router from the separate route file, often with a common base path.
    Hint

    This action integrates the router into the main application's middleware stack.

    Answer

    mount

  37. 37
    A common path, such as /todos, specified in app.use() for a router, will be
    _____
    to every route defined within that router file.
    Hint

    This path acts as a prefix for all routes in the mounted router.

    Answer

    prepended

  38. 38
    Middleware is a function that runs
    _____
    a request actually reaches the route handler.
    Hint

    It acts as an intermediary step in the request-response cycle.

    Answer

    before

  39. 39
    A common use case for middleware is adding
    _____
    , where it checks if a user is authorized to make a request.
    Hint

    This process verifies the identity of a user or client.

    Answer

    authentication

  40. 40
    Middleware functions take req, res, and `
    _____
    ` as parameters.
    Hint

    This parameter is a function that, when called, passes control to the next middleware function.

    Answer

    next

  41. 41
    If a middleware determines that a user is not authenticated, it can send a `
    _____
    ` HTTP status code, indicating a forbidden request.
    Hint

    This status code means the server understood the request but refuses to authorize it.

    Answer

    403

1 of 41
Question 1 of 41

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent