Express.js Quiz - MCQ - Multiple Choice Questions
Q. What is Express.js?
A. A front-end JavaScript frameworkB. A back-end Node.js web framework
C. A mobile app development toolkit
D. A database management system
Q. How do you install Express.js in a Node.js project?
A. npm install expressB. yarn add express
C. Both A and B
D. None of the above
Q. What is the purpose of middleware in Express.js?
A. To handle requests and responsesB. To manage routing and URL mapping
C. To provide additional functionality and processing
D. All of the above
Q. How do you define a route in Express.js?
A. app.get('/route', function(req, res) {// route handling logic
});
B. app.route('/route').get(function(req, res) {
// route handling logic
});
C. app.use('/route', function(req, res) {
// route handling logic
});
D. app.set('/route', function(req, res) {
// route handling logic
});
Q. What is the purpose of the res.send() method in Express.js?
A. To send a response back to the clientB. To set the HTTP status code
C. To set headers in the response
D. All of the above
Q. How can you access form data in a POST request using Express.js?
A. req.bodyB. req.params
C. req.query
D. req.headers
Q. What is the purpose of the next() function in Express.js middleware?
A. To skip the current middleware functionB. To pass control to the next middleware function
C. To end the request-response cycle
D. To send a response to the client
Q. How can you render a view in Express.js using EJS?
A. res.render('viewName', { data: 'value' });B. res.view('viewName', { data: 'value' });
C. res.template('viewName', { data: 'value' });
D. res.ejs('viewName', { data: 'value' });
Q. How can you set a custom port for your Express.js application?
A. app.set('port', 3000);B. app.use(3000);
C. app.listen(3000);
D. app.port = 3000;
Q. How can you handle errors in Express.js middleware?
A. Using the next(error) syntaxB. Throwing an Error object
C. Using the res.error() method
D. All of the above