0% found this document useful (0 votes)
4 views7 pages

Module 4

The document provides a comprehensive overview of Express.js, a web application framework for Node.js, including installation, core concepts, and usage of various methods. Key topics covered include defining routes, handling requests and responses, middleware, and error handling. It also outlines the HTTP methods used for different operations such as creating, updating, retrieving, and deleting resources.

Uploaded by

sija23aids
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

Module 4

The document provides a comprehensive overview of Express.js, a web application framework for Node.js, including installation, core concepts, and usage of various methods. Key topics covered include defining routes, handling requests and responses, middleware, and error handling. It also outlines the HTTP methods used for different operations such as creating, updating, retrieving, and deleting resources.

Uploaded by

sija23aids
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Section 1: Express JS

-> What is [Link].


a) A database management system for [Link].
b) A front-end framework for building user interfaces.
c) A web application framework for [Link].
d) A testing framework for JavaScript.
Solution: c) A web application framework for [Link].
-> How do you install [Link] in your project?
a) npm install express
b) yarn add [Link]
c) npm get express
d) install express
Solution: a) npm install express
-> Which method is used to create an Express application instance?
a) [Link]()
b) new express()
c) express()
d) [Link]()
Solution: c) express()
-> What is the purpose of [Link]() in [Link]?
a) To define a route handler.
b) To register middleware that will be applied to incoming requests.
c) To send a response to the client.
d) To start the server.
Solution: b) To register middleware that will be applied to incoming requests.
-> Which of the following is a core concept in [Link] for handling requests
and responses?
a) Templates
b) Middleware
c) Databases
d) Front-end components
Solution: b) Middleware
-> How do you define a GET route in [Link]?
a) [Link]('/path', callback)
b) [Link]('/path', callback)
c) [Link]('/path').get(callback)
d) [Link]('/path', callback)
Solution: b) [Link]('/path', callback)
-> How can you send a JSON response in [Link]?
a) [Link](data)
b) [Link](data)
c) [Link]([Link](data))
d) [Link](data)
Solution: b) [Link](data)
-> Which object in an Express route handler contains request parameters (e.g.,
from :id in a
URL)?
a) [Link]
b) [Link]
c) [Link]
d) [Link]
Solution: c) [Link]
-> What is the default port number for an [Link] server if not specified?
a) 80
b) 8080
c) 3000
d) 5000
Solution: c) 3000
-> How do you start an [Link] server to listen for incoming requests?
a) [Link](port)
b) [Link](port, callback)
c) [Link](port)
d) [Link](port)
Solution: b) [Link](port, callback)
-> Which middleware is commonly used in [Link] to parse incoming request
bodies (e.g.,
JSON or URL-encoded data)?
a) [Link]
b) body-parser
c) cookie-parser
d) morgan
Solution: b) body-parser
-> How do you serve static files (e.g., HTML, CSS, images) in [Link]?
a) [Link]([Link]('public'))
b) [Link]('public')
c) [Link]('public')
d) [Link]('public')
Solution: a) [Link]([Link]('public'))
-> What is the purpose of next() in [Link] middleware?
a) To terminate the request-response cycle.
b) To pass control to the next middleware function in the stack.
c) To send an error response.
d) To redirect the client to another URL.
Solution: b) To pass control to the next middleware function in the stack.
-> How do you handle errors in [Link]?
a) Using try-catch blocks only.
b) By defining error-handling middleware with four arguments (err, req, res,
next).
c) Errors are automatically handled by [Link].
d) By using [Link]('uncaughtException').
Solution: b) By defining error-handling middleware with four arguments (err,
req, res, next).
-> Which of the following is NOT a built-in [Link] middleware?
a) [Link]()
b) [Link]()
c) [Link]()
d) [Link]()
Solution: c) [Link]() (This is a third-party module)
-> How do you access query parameters (e.g., ?name=John) in an [Link]
route handler?
a) [Link]
b) [Link]
c) [Link]
d) [Link]
Solution: b) [Link]
-> What is a "router" in [Link]?
a) A mechanism for defining database connections.
b) A way to group route handlers and middleware for specific paths.
c) A tool for server-side rendering.
d) A component for managing user authentication.
Solution: b) A way to group route handlers and middleware for specific paths
-> How do you create an Express Router instance?
a) [Link]()
b) new Router()
c) [Link]()
d) [Link]()
Solution: a) [Link]()
-> Which HTTP method is typically used for creating new resources?
a) GET
b) PUT
c) POST
d) DELETE
Solution: c) POST
-> Which HTTP method is typically used for updating existing resources?
a) GET
b) PUT
c) POST
d) DELETE
Solution: b) PUT
-> Which HTTP method is typically used for retrieving resources?
a) GET
b) PUT
c) POST
d) DELETE
Solution: a) GET
-> Which HTTP method is typically used for deleting resources?
a) GET
b) PUT
c) POST
d) DELETE
Solution: d) DELETE
-> What is the purpose of [Link]() in [Link]?
a) To send a file as a response.
b) To redirect the client to a different URL.
c) To render a view template.
d) To send a JSON response.
Solution: b) To redirect the client to a different URL.
-> How can you set a custom header in an [Link] response?
a) [Link]('Content-Type', 'text/plain')
b) [Link]('Content-Type', 'text/plain')
c) [Link]('Content-Type', 'text/plain')
d) [Link]('Content-Type', 'text/plain')
Solution: d) [Link]('Content-Type', 'text/plain')
-> What does the [Link] object typically contain in an [Link] route
handler?
a) URL parameters.
b) Query parameters.
c) Data sent in the request body (e.g., from a POST request).
d) HTTP headers.
Solution: c) Data sent in the request body (e.g., from a POST request).

You might also like