Express.js, a minimalist web framework for Node.js, has become an essential tool for many web developers. This quiz is designed to test your foundational knowledge of Express.js. For each question, choose the best answer. Explanations are provided for each correct answer to help you understand the concepts better.
1. What is Express.js?
A. A database
B. A frontend framework
C. A web server framework for Node.js
D. An operating system
2. Which method sends a JSON response in Express.js?
A. res.json()
B. res.send()
C. res.sendFile()
D. res.render()
3. How do you capture query parameters in Express routes?
A. req.data
B. req.params
C. req.query
D. req.body
4. Which of these is not a core feature of Express?
A. Middleware
B. Routing
C. Templating
D. ORM
5. To serve static files like images, CSS files, and JavaScript files in Express, you use:
A. express.static()
B. res.sendFile()
C. app.static()
D. res.sendStatic()
6. In Express.js, how do you redirect a user to another page?
A. res.send('/new-url')
B. res.redirect('/new-url')
C. res.goto('/new-url')
D. app.redirect('/new-url')
7. What's the primary use of middleware in Express?
A. Data storage
B. Error handling
C. Execution of functions in the request-response cycle
D. Frontend rendering
8. What method is used to create a middleware in Express?
A. app.middleware()
B. app.use()
C. express.middleware()
D. express.use()
9. How do you send a status of 404 and a message 'Not Found' in Express?
A. res.status(404).message('Not Found')
B. res.status(404).send('Not Found')
C. res.send(404, 'Not Found')
D. res.sendStatus(404, 'Not Found')
10. Which of these methods will handle HTTP POST requests in an Express app?
A. app.post()
B. app.get()
C. app.all()
D. app.put()
11. How do you capture data sent in the body of a POST request in Express?
A. req.params
B. req.body
C. req.data
D. req.query
12. To use req.body, what middleware must be used with Express?
A. express.urlencoded()
B. express.query()
C. express.static()
D. express.getbody()
13. Which middleware in Express.js helps in handling JSON data from POST requests?
A. express.json()
B. express.urlencoded()
C. express.parse()
D. express.data()
14. Which of the following methods is used to render a view in Express.js?
A. res.view()
B. res.page()
C. res.sendView()
D. res.render()
15. If you want to set a cookie in Express.js, which method would you use?
A. res.setCookie()
B. res.cookie()
C. res.saveCookie()
D. res.putCookie()
16. In Express, if you wanted a middleware function to be executed for every request, where would you place it?
A. At the end of all route definitions
B. Before all route definitions
C. Inside each route definition
D. Inside the app's main file
17. What will next() function do in Express middleware?
A. It will end the response cycle.
B. It will pass control to the next middleware function.
C. It will restart the request-response cycle.
D. It will throw an error.
18. To serve static files in Express, which built-in middleware would you use?
A. express.static()
B. express.file()
C. express.serve()
D. express.folder()
19. What does app.all() method do in Express.js?
A. It handles all HTTP methods.
B. It handles only POST and GET methods.
C. It restarts the app.
D. It closes all open routes.
20. Which function in Express.js wraps an asynchronous function to catch all the errors?
A. catchAsync()
B. asyncWrapper()
C. wrapAsync()
D. handleAsync()
21. If you want to set several properties on a response at once in Express.js, which method would you use?
A. res.set()
B. res.properties()
C. res.headerSet()
D. res.multiSet()
22. How can you access the query string parameters in Express.js?
A. req.params
B. req.data
C. req.body
D. req.query
23. What is the primary purpose of the Express 'Router'?
A. To route different files in the file system.
B. To divide the application into modular, mountable route handlers.
C. To connect to different databases.
D. To parse incoming requests.
24. How do you get the HTTP method (like GET, POST) of a client's request in Express?
A. req.methodType()
B. req.httpMethod
C. req.type()
D. req.method
25. How do you retrieve the value of a specific cookie sent in a request in Express.js?
A. req.cookie.value
B. req.cookies[cookieName]
C. req.get('cookieName')
D. req.values.cookieName
Comments
Post a Comment
Leave Comment