Skip to content
QuiznExam

Express.js Basics & Routing

Test your knowledge of Express.js basics and routing in Node.js, including creating servers, routes, HTTP methods, middleware, request and response objects, route parameters, query strings, and route handlers.

15
Questions
12 min
Time limit
Medium
Difficulty

No sign-up needed · Last updated:

Save your score

At least 8 characters.

Forgot password?

Related quizzes

All 15 questions and answers Spoilers: this shows the questions and answers. Try the quiz first! Open
  1. 1. What is Express.js?

    • A. A web framework for Node.js
    • B. A database management system
    • C. A frontend CSS framework
    • D. A JavaScript testing language
    Show answer

    A. A web framework for Node.js

    Express.js is a lightweight web application framework for Node.js commonly used to build web servers and APIs.

  2. 2. Which command is commonly used to install Express.js in a Node.js project?

    • A. npm install express
    • B. npm add node-express-only
    • C. node install express
    • D. npm create express
    Show answer

    A. npm install express

    The npm install express command installs Express.js as a dependency in the current Node.js project.

  3. 3. How do you create an Express application?

    • A. const app = express()
    • B. const app = new ExpressServer()
    • C. const app = node.express()
    • D. const app = createExpressServer()
    Show answer

    A. const app = express()

    Calling the imported express function creates an Express application instance.

  4. 4. Which method is used to define a GET route in Express?

    • A. app.get()
    • B. app.fetch()
    • C. app.request()
    • D. app.routeGet()
    Show answer

    A. app.get()

    The app.get() method defines a route that responds to HTTP GET requests.

  5. 5. Which method is used to define a POST route in Express?

    • A. app.post()
    • B. app.send()
    • C. app.create()
    • D. app.submit()
    Show answer

    A. app.post()

    The app.post() method defines a route handler for HTTP POST requests.

  6. 6. Which object contains information about the incoming HTTP request in an Express route handler?

    • A. req
    • B. res
    • C. app
    • D. server
    Show answer

    A. req

    The request object, commonly named req, contains information such as parameters, query strings, headers, and the request body.

  7. 7. Which object is used to send a response back to the client?

    • A. res
    • B. req
    • C. app
    • D. router
    Show answer

    A. res

    The response object, commonly named res, provides methods such as res.send() and res.json() for sending responses.

  8. 8. Which Express method can be used to send a JSON response?

    • A. res.json()
    • B. res.object()
    • C. res.data()
    • D. res.sendJsonOnly()
    Show answer

    A. res.json()

    The res.json() method sends a JSON response to the client.

  9. 9. How can a route parameter be defined in an Express route?

    • A. /users/:id
    • B. /users/{id}
    • C. /users/[id]
    • D. /users/<id>
    Show answer

    A. /users/:id

    Express uses a colon before a parameter name, such as /users/:id. The value can then be accessed through req.params.id.

  10. 10. Where can you access the value of an Express route parameter?

    • A. req.params
    • B. req.queryParams
    • C. res.params
    • D. app.paramsOnly
    Show answer

    A. req.params

    Route parameters such as :id are available through the req.params object.

  11. 11. For the URL /products?category=books, where can the category value be accessed in Express?

    • A. req.query.category
    • B. req.params.category
    • C. res.query.category
    • D. app.query.category
    Show answer

    A. req.query.category

    Query string values are available through req.query, so category can be accessed using req.query.category.

  12. 12. What is Express middleware?

    • A. A function that has access to the request, response, and next middleware function
    • B. A database used by Express
    • C. A replacement for Node.js
    • D. A frontend component library
    Show answer

    A. A function that has access to the request, response, and next middleware function

    Express middleware functions can inspect or modify requests and responses, end the request-response cycle, or pass control to the next middleware.

  13. 13. Which function is commonly called by Express middleware to pass control to the next middleware or route handler?

    • A. next()
    • B. continue()
    • C. forward()
    • D. proceed()
    Show answer

    A. next()

    Calling next() passes control to the next middleware function in the request processing chain.

  14. 14. Which method can be used to mount an Express Router at a specific path?

    • A. app.use()
    • B. app.mountRoute()
    • C. app.router()
    • D. app.attach()
    Show answer

    A. app.use()

    The app.use() method can mount middleware or an Express Router at a specified path, such as app.use('/api', router).

  15. 15. Which HTTP method is commonly used to update an existing resource completely?

    • A. PUT
    • B. GET
    • C. OPTIONS
    • D. HEAD
    Show answer

    A. PUT

    PUT is commonly used to replace or completely update an existing resource, while PATCH is commonly used for partial updates.