Express.js Quiz ( Beginner ) - All Questions
This beginner-level Express.js quiz is designed for developers who are starting with backend development using Node.js. It covers core Express concepts like routing, middleware, request-response handling, and basic server setup in a simple, interview-friendly way.
Question 1: What is Express.js?
- A database
- A Node.js web framework
- A frontend library
- A programming language
Explanation: Express.js is a web framework built on top of Node.js.
Question 2: Express.js is mainly used for?
- Building mobile apps
- Creating APIs and web servers
- Styling web pages
- Managing databases
Explanation: Express.js helps build APIs and server-side applications.
Question 3: Which command installs Express.js?
- npm add express
- npm install express
- node install express
- express install
Explanation: npm install express installs the Express framework.
Question 4: Which function creates an Express application?
- express()
- createApp()
- new Express()
- app()
Explanation: Calling express() creates an Express app instance.
Question 5: Which object represents the incoming request?
Explanation: req represents the HTTP request.
Question 6: Which object is used to send a response?
Explanation: res is used to send data back to the client.
Question 7: Which HTTP method is used to fetch data?
Explanation: GET is used to retrieve data from the server.
Question 8: Which HTTP method is used to create data?
Explanation: POST is used to create new resources.
Question 9: What does app.listen() do?
- Handles routing
- Starts the server
- Parses requests
- Stops the server
Explanation: app.listen() starts the Express server.
Question 10: Which port is commonly used for Express apps?
Explanation: Port 3000 is commonly used during development.
Question 11: What is middleware in Express?
- A database layer
- A function that handles requests and responses
- A frontend component
- A routing method
Explanation: Middleware functions run between request and response.
Question 12: Which middleware parses JSON request bodies?
- express.urlencoded()
- express.json()
- bodyParser()
- jsonParser()
Explanation: express.json() parses JSON payloads.
Question 13: Which middleware parses URL-encoded data?
- express.urlencoded()
- express.json()
- urlParser()
- bodyParser.json()
Explanation: express.urlencoded() parses form data.
Question 14: Which method defines a GET route?
- app.fetch()
- app.route()
- app.get()
- app.read()
Explanation: app.get() defines a GET route.
Question 15: Which method defines a POST route?
- app.create()
- app.send()
- app.post()
- app.write()
Explanation: app.post() handles POST requests.
Question 16: What does res.send() do?
- Ends the request
- Sends response data
- Redirects request
- Parses JSON
Explanation: res.send() sends data to the client.
Question 17: What does res.json() do?
- Sends plain text
- Sends HTML
- Sends JSON response
- Parses JSON
Explanation: res.json() sends a JSON response.
Question 18: Which method sets the HTTP status code?
- res.code()
- res.status()
- res.sendStatus()
- res.header()
Explanation: res.status() sets the response status code.
Question 19: What does app.use() do?
- Defines routes only
- Registers middleware
- Starts server
- Stops middleware
Explanation: app.use() registers middleware functions.
Question 20: Which middleware logs HTTP requests?
Explanation: Morgan is used for logging HTTP requests.
Question 21: Which package helps handle environment variables?
Explanation: dotenv loads environment variables from a file.
Question 22: Which file usually contains Express server setup?
- package.json
- server.js or app.js
- index.html
- config.env
Explanation: Server configuration is usually in app.js or server.js.
Question 23: Which HTTP status code means success?
Explanation: 200 indicates a successful request.
Question 24: Which status code means resource not found?
Explanation: 404 means the resource was not found.
Question 25: How do you send a redirect response?
- res.move()
- res.redirect()
- res.route()
- res.forward()
Explanation: res.redirect() sends a redirect response.
Question 26: What does next() do in middleware?
- Stops request
- Ends response
- Passes control to next middleware
- Restarts server
Explanation: next() passes control to the next middleware.
Question 27: Which Express feature helps organize routes?
- Controllers
- Routers
- Models
- Views
Explanation: Express Router helps organize routes.
Question 28: Which method creates a router?
- express.route()
- express.router()
- express.Router()
- app.router()
Explanation: express.Router() creates modular routes.
Question 29: Which middleware handles CORS?
- helmet
- cors
- morgan
- body-parser
Explanation: cors enables Cross-Origin Resource Sharing.
Question 30: Which command starts an Express app?
- node app.js
- npm express
- express start
- npm install
Explanation: node app.js runs the Express server.
Question 31: Which object contains route parameters?
- req.body
- req.query
- req.params
- req.headers
Explanation: req.params contains route parameters.
Question 32: Which object contains query string values?
- req.body
- req.query
- req.params
- req.cookies
Explanation: req.query holds query string data.
Question 33: Which object contains POST request data?
- req.query
- req.params
- req.body
- req.headers
Explanation: req.body contains POST data.
Question 34: Which middleware helps secure HTTP headers?
Explanation: helmet helps secure HTTP headers.
Question 35: Which Express feature supports template engines?
- Views
- Models
- Controllers
- Middlewares
Explanation: Views allow template engine integration.
Question 36: Which template engine is commonly used with Express?
- Handlebars
- EJS
- Pug
- All of the above
Explanation: Express supports multiple template engines.
Question 37: What does express.static() do?
- Creates routes
- Serves static files
- Handles APIs
- Parses JSON
Explanation: express.static() serves static assets.
Question 38: Which folder commonly stores static files?
Explanation: Static assets are stored in the public folder.
Question 39: Which HTTP status code indicates server error?
Explanation: 500 indicates a server error.
Question 40: What does REST stand for?
- Remote Execution State Transfer
- Representational State Transfer
- Response State Transfer
- Request Execution Syntax Tree
Explanation: REST stands for Representational State Transfer.
Question 41: Which Express method handles all HTTP methods?
- app.all()
- app.any()
- app.use()
- app.route()
Explanation: app.all() handles all HTTP methods.
Question 42: Which status code indicates unauthorized access?
Explanation: 401 indicates unauthorized access.
Question 43: Which status code indicates forbidden access?
Explanation: 403 means access is forbidden.
Question 44: Which method is used to chain route handlers?
- app.chain()
- app.route()
- app.link()
- app.use()
Explanation: app.route() allows chaining handlers.
Question 45: Which Express feature improves code readability?
- Inline routing
- Router modules
- Global variables
- Synchronous code
Explanation: Router modules organize code cleanly.
Question 46: What is Express.js built on top of?
- React
- Node.js
- MongoDB
- HTTP/2
Explanation: Express.js is built on Node.js.
Question 47: What is the main benefit of Express.js?
- Frontend rendering
- Minimal and flexible backend framework
- Database management
- Mobile UI creation
Explanation: Express is minimal and flexible for backend development.