img
Express JS

Express.js is a minimalist web application framework for Node.js. It simplifies building web servers and APIs with its flexibility and extensive middleware support.

Last updated on:- 7th June 2023


1.
What is Express.js ?
A template engine
A database management system
A web application framework
A version control system

Express.js is a web application framework for Node.js. It provides a set of features and tools for building robust and scalable web applications and APIs.


2.
What is the purpose of the 'app.use' method in Express.js ?
To handle HTTP GET requests
To define route handlers
To set up middleware functions
To render HTML templates

The 'app.use' method in Express.js is used to set up middleware functions. Middleware functions are functions that have access to the request and response objects, and can modify or augment them.


3.
Which method is used to handle an HTTP GET request in Express.js ?
app.get()
app.post()
app.put()
app.delete()

The 'app.get()' method in Express.js is used to handle an HTTP GET request. It takes a path and a callback function as arguments, and the callback function is executed when a GET request is made to the specified path.


4.
What is the purpose of the 'req.params' object in Express.js ?
To access query parameters
To access route parameters
To access request headers
To access request cookies

The 'req.params' object in Express.js is used to access route parameters. Route parameters are placeholders in the route path that can capture values specified in the URL.


5.
What is the purpose of the 'req.query' object in Express.js ?
To access query parameters
To access route parameters
To access request headers
To access request cookies

The 'req.query' object in Express.js is used to access query parameters. Query parameters are key-value pairs in the URL that are used to provide additional data to the server.


6.
What is middleware in Express.js ?
A database management system
A template engine
A function that has access to the request and response objects
A version control system

Middleware in Express.js is a function that has access to the request and response objects. It can perform tasks such as modifying the request or response,invoking the next middleware function, or terminating the request-response cycle.


7.
Which template engine is commonly used with Express.js ?
Pug
Handlebars
EJS
All of the above

Express.js supports multiple template engines, including Pug (formerly Jade), Handlebars, and EJS. Developers can choose the template engine that best fits their needs and preferences.


8.
What is the purpose of the 'res.render' method in Express.js ?
To handle HTTP GET requests
To define route handlers
To send JSON data
To render a view template

The 'res.render' method in Express.js is used to render a view template. It takes the name of the template file as an argument and combines it with the data to generate an HTML response.


9.
What is the purpose of the 'app.listen' method in Express.js ?
To handle HTTP requests
To start the Express.js application
To set up middleware functions
To render HTML templates

The 'app.listen' method in Express.js is used to start the Express.js application and listen for incoming HTTP requests. It takes a port number and an optional callback function as arguments.


10.
What is the purpose of the 'app.use(express.json())' middleware in Express.js ?
To handle HTTP GET requests
To parse JSON data in the request body
To set up middleware functions
To render HTML templates

The 'app.use(express.json())' middleware in Express.js is used to parse JSON data in the request body. It automatically parses the request body and makes the parsed data available in the 'req.body' property.


11.
What is the purpose of the 'app.param' method in Express.js ?
To handle HTTP GET requests
To define route handlers
To set up middleware functions
To handle route parameters

The 'app.param' method in Express.js is used to handle route parameters. It allows you to define middleware functions that are executed when a specific route parameter is present in the URL.


6.
What is the purpose of the 'app.post' method in Express.js ?
To define a route handler for GET requests
To define a route handler for POST requests
To define a route handler for PUT requests
To define a route handler for DELETE requests

The 'app.post' method in Express.js is used to define a route handler for POST requests. It specifies a callback function that will be executed when a POST request with a matching route is received by the server.


13.
What is the purpose of the 'res.send' method in Express.js ?
To handle HTTP GET requests
To send JSON data
To render a view template
To send a response to the client

The 'res.send' method in Express.js is used to send a response to the client. It can send various types of data, including plain text, HTML, JSON, and more.


14.
What is the purpose of the 'res.redirect' method in Express.js ?
To handle HTTP GET requests
To send JSON data
To redirect the client to a different URL
To render a view template

The 'res.redirect' method in Express.js is used to redirect the client to a different URL. It sends a redirect response to the client with the specified URL, causing the client to make a new request to that URL.


15.
What is the purpose of the 'app.set' method in Express.js ?
To handle HTTP GET requests
To set up middleware functions
To configure application settings
To render HTML templates

The 'app.set' method in Express.js is used to configure application settings. It allows you to set various properties and options for your Express.js application.


16.
What is the purpose of the 'res.status' method in Express.js ?
To handle HTTP GET requests
To send JSON data
To render a view template
To set the HTTP status code of the response

The 'res.status' method in Express.js is used to set the HTTP status code of the response. It allows you to specify the status code that should be sent to the client.


17.
What is the purpose of 'express.static' middleware in Express.js ?
To handle HTTP GET requests
To define route handlers
To serve static files
To render HTML templates

The 'express.static' middleware in Express.js is used to serve static files, such as HTML, CSS, and JavaScript files. It can be used to serve files from a specific directory.


18.
How can you retrieve request parameters in Express.js ?
Using the 'req.query' object
Using the 'req.body' object
Using the 'req.params' object
All of the above

In Express.js, you can retrieve request parameters using the 'req.query' object for query parameters, the 'req.body' object for request bodies, and the 'req.params' object for route parameters. All of these objects provide different ways to access and extract data from incoming requests.


19.
What is a route handler in Express.js ?
A function that handles HTTP requests for a specific route
A function that handles errors in the application
A function that handles middleware errors
A function that renders HTML templates

A route handler in Express.js is a function that handles HTTP requests for a specific route. It is executed when a matching request is received and can perform actions such as accessing a database, processing data, and sending a response.


20.
What is the purpose of the 'req.cookies' object in Express.js ?
To access query parameters
To access route parameters
To access request headers
To access request cookies

The 'req.cookies' object in Express.js is used to access request cookies. It provides access to the cookies sent by the client in the request.


21.
What is the purpose of the 'app.locals' object in Express.js ?
To handle HTTP GET requests
To set up middleware functions
To store application-level data
To render HTML templates

The 'app.locals' object in Express.js is used to store application-level data. It allows you to store variables or data that are accessible across different routes and views within the same application.


22.
What is the purpose of the 'req.session' object in Express.js ?
To access query parameters
To access route parameters
To access request headers
To manage session data

The 'req.session' object in Express.js is used to manage session data. Sessions allow you to store data that is associated with a specific user or client across multiple requests.


23.
What is the purpose of the 'express.Router' class in Express.js ?
To handle HTTP GET requests
To define route handlers
To set up middleware functions
To render HTML templates

The 'express.Router' class in Express.js is used to define route handlers. It allows you to create modular and reusable route handlers that can be mounted as middleware.


24.
What is the purpose of the 'app.route' method in Express.js ?
To handle HTTP GET requests
To define route handlers
To set up middleware functions
To render HTML templates

The 'app.route' method in Express.js is used to define route handlers for a specific route. It allows you to chain multiple HTTP verb methods for a single route path.


25.
What is the purpose of the 'express.json' middleware in Express.js ?
To handle HTTP GET requests
To parse JSON data in the request body
To set up middleware functions
To render HTML templates

The 'express.json' middleware in Express.js is used to parse JSON data in the request body. It automatically parses the request body and makes the parsed data available in the 'req.body' property.


26.
What is the purpose of the 'express.urlencoded' middleware in Express.js ?
To handle HTTP GET requests
To parse JSON data in the request body
To set up middleware functions
To parse URL-encoded data in the request body

The 'express.urlencoded' middleware in Express.js is used to parse URL-encoded data in the request body. It automatically parses the request body and makes the parsed data available in the 'req.body' property.


27.
What is the purpose of the 'app.all' method in Express.js ?
To handle all types of HTTP requests
To define route handlers
To set up middleware functions
To render HTML templates

The 'app.all' method in Express.js is used to handle all types of HTTP requests (GET, POST, PUT, DELETE, etc.) for a specific route. It is often used for global middleware or error handling.


28.
What is the purpose of the 'req.app' property in Express.js ?
To access query parameters
To access route parameters
To access the Express.js application instance
To access request cookies

The 'req.app' property in Express.js is used to access the Express.js application instance. It provides access to the instance of the Express.js application handling the current request.


29.
What is the purpose of the 'req.route' property in Express.js ?
To access query parameters
To access route parameters
To access request headers
To access route information

The 'req.route' property in Express.js is used to access route information. It provides information about the currently matched route, including the route path and any parameters.


30.
What is the purpose of the 'req.query' object in Express.js ?
To access query parameters
To access route parameters
To access request headers
To access request cookies

The 'req.query' object in Express.js is used to access query parameters. Query parameters are key-value pairs that are appended to the URL and can be used to pass data to the server.

img

"Embrace curiosity, unlock knowledge"

Copyright © 2023 - Some rights reserved

Made with

in INDIA