1Which built-in Node.js module is primarily used to create a web server?
A.fs
B.http
C.url
D.server
Correct Answer: http
Explanation:The 'http' module is the built-in Node.js module capable of creating an HTTP server.
Incorrect! Try again.
2Which method of the HTTP module is used to initialize a server?
A.http.initServer()
B.http.createServer()
C.http.startServer()
D.http.newServer()
Correct Answer: http.createServer()
Explanation:The createServer() method turns the computer into an HTTP server.
Incorrect! Try again.
3What arguments does the request listener callback function in http.createServer() accept?
A.(request, response)
B.(req, data)
C.(response, error)
D.(data, status)
Correct Answer: (request, response)
Explanation:The callback function receives two arguments: the incoming request object (req) and the outgoing response object (res).
Incorrect! Try again.
4Which method is used to make the Node.js HTTP server accept connections on a specific port?
A.server.start()
B.server.run()
C.server.listen()
D.server.bind()
Correct Answer: server.listen()
Explanation:The server.listen() method makes the server listen for incoming requests on a specified port.
Incorrect! Try again.
5In a raw Node.js server, where is the request metadata (like headers and URL) stored?
A.In the response object
B.In the global scope
C.In the request object
D.In the file system
Correct Answer: In the request object
Explanation:The request object (req) contains information about the incoming HTTP request, including headers, URL, and method.
Incorrect! Try again.
6Which property of the request object holds the part of the URL after the domain name?
A.req.path
B.req.url
C.req.href
D.req.link
Correct Answer: req.url
Explanation:The req.url property holds the request URL string.
Incorrect! Try again.
7Which method is used to send a chunk of the response body in the native HTTP module?
A.res.send()
B.res.write()
C.res.push()
D.res.log()
Correct Answer: res.write()
Explanation:res.write() sends a chunk of the response body. It can be called multiple times before res.end().
Incorrect! Try again.
8What must be called to complete the response and send it to the client in the native HTTP module?
A.res.stop()
B.res.finish()
C.res.end()
D.res.complete()
Correct Answer: res.end()
Explanation:res.end() signals to the server that all of the response headers and body have been sent.
Incorrect! Try again.
9How do you set the HTTP status code to 404 using the native response object?
A.res.code = 404
B.res.statusCode = 404
C.res.setStatus(404)
D.res.status(404)
Correct Answer: res.statusCode = 404
Explanation:In the native HTTP module, you set the statusCode property directly on the response object.
Incorrect! Try again.
10Which method is used to write the status code and response headers simultaneously in native Node.js?
A.res.writeHead()
B.res.setHeader()
C.res.sendHeader()
D.res.writeHeader()
Correct Answer: res.writeHead()
Explanation:res.writeHead(statusCode, [headers]) writes the status code and headers to the response stream.
Incorrect! Try again.
11What is the correct HTTP status code for a successful request?
A.200
B.201
C.400
D.500
Correct Answer: 200
Explanation:200 OK is the standard response for successful HTTP requests.
Incorrect! Try again.
12What is the correct HTTP status code for 'Internal Server Error'?
A.404
B.500
C.301
D.403
Correct Answer: 500
Explanation:500 represents a generic error message given when an unexpected condition was encountered on the server.
Incorrect! Try again.
13When sending JSON data using native Node.js, what should the 'Content-Type' header be set to?
A.text/html
B.text/json
C.application/json
D.application/javascript
Correct Answer: application/json
Explanation:The standard MIME type for JSON data is 'application/json'.
Incorrect! Try again.
14How is basic routing typically implemented in a native Node.js HTTP server?
A.Using a router file
B.Using if/else statements checking req.url
C.Using switch/case on req.body
D.It handles routing automatically
Correct Answer: Using if/else statements checking req.url
Explanation:Native routing involves manually checking the req.url property and req.method inside conditional statements.
Incorrect! Try again.
15Which HTTP method is used to request data from a specified resource?
A.POST
B.PUT
C.DELETE
D.GET
Correct Answer: GET
Explanation:The GET method is used to retrieve data from a server.
Incorrect! Try again.
16Which HTTP method is commonly used to submit data to be processed to a specified resource?
A.GET
B.POST
C.HEAD
D.OPTIONS
Correct Answer: POST
Explanation:The POST method is used to send data to a server to create/update a resource.
Incorrect! Try again.
17What is Express.js?
A.A database for Node.js
B.A fast, unopinionated web framework for Node.js
C.A front-end library
D.A strict MVC framework
Correct Answer: A fast, unopinionated web framework for Node.js
Explanation:Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.
Incorrect! Try again.
18Which command is used to install Express in a Node.js project?
A.node install express
B.npm install express
C.npm get express
D.install express
Correct Answer: npm install express
Explanation:npm (Node Package Manager) is used to install packages like Express.
Incorrect! Try again.
19What is the first step to using Express in a file after installation?
A.const app = express()
B.require('express')
C.import express from 'node'
D.start express
Correct Answer: require('express')
Explanation:You must require the module first: const express = require('express').
Incorrect! Try again.
20How do you initialize an Express application?
A.const app = new Express()
B.const app = express()
C.const app = createApplication()
D.const app = start()
Correct Answer: const app = express()
Explanation:Calling the top-level express() function exported by the module creates an Express application.
Incorrect! Try again.
21Which Express method is used to handle GET requests?
A.app.fetch()
B.app.retrieve()
C.app.get()
D.app.read()
Correct Answer: app.get()
Explanation:app.get() routes HTTP GET requests to the specified path with the specified callback functions.
Incorrect! Try again.
22In Express, what method is used to send a response and automatically set the Content-Type?
A.res.write()
B.res.send()
C.res.emit()
D.res.dispatch()
Correct Answer: res.send()
Explanation:res.send() sends the HTTP response. It automatically sets the Content-Type based on the body parameter type.
Incorrect! Try again.
23How do you access route parameters (e.g., /users/:id) in Express?
A.req.query
B.req.body
C.req.params
D.req.route
Correct Answer: req.params
Explanation:req.params contains properties mapped to the named route 'parameters'.
Incorrect! Try again.
24How do you access query string parameters (e.g., ?search=term) in Express?
A.req.params
B.req.query
C.req.search
D.req.url
Correct Answer: req.query
Explanation:req.query is an object containing a property for each query string parameter in the route.
Incorrect! Try again.
25Which Express method starts the server listening for connections?
A.app.run()
B.app.listen()
C.app.start()
D.app.init()
Correct Answer: app.listen()
Explanation:Like the native http module, Express uses app.listen() to bind and listen for connections.
Incorrect! Try again.
26What is the purpose of 'body-parser' middleware?
A.To parse the URL
B.To validate the response
C.To parse incoming request bodies
D.To send JSON data
Correct Answer: To parse incoming request bodies
Explanation:body-parser extracts the entire body portion of an incoming request stream and exposes it on req.body.
Incorrect! Try again.
27Before Express 4.16.0, body-parser was a separate install. How do you access JSON parsing now in modern Express?
A.express.body()
B.express.json()
C.express.parse()
D.It is not supported
Correct Answer: express.json()
Explanation:Modern Express includes body-parser functionality via express.json() middleware.
Incorrect! Try again.
28Which middleware parses incoming requests with URL-encoded payloads?
A.express.urlencoded()
B.express.text()
C.express.raw()
D.express.form()
Correct Answer: express.urlencoded()
Explanation:express.urlencoded() is a built-in middleware function in Express that parses incoming requests with urlencoded payloads.
Incorrect! Try again.
29If body-parser is not used, what is the value of req.body for a POST request in Express by default?
A.null
B.undefined
C.An empty object {}
D.An empty string
Correct Answer: undefined
Explanation:By default, req.body is undefined, and is populated only when you use body-parsing middleware.
Incorrect! Try again.
30What does the extended: true option in urlencoded() middleware do?
A.Allows parsing of rich objects and arrays
B.Enables HTTPS
C.Increases the body size limit
D.Parses XML data
Correct Answer: Allows parsing of rich objects and arrays
Explanation:When set to true, the 'qs' library is used allows for a JSON-like experience with URL-encoded data.
Incorrect! Try again.
31What is express.Router used for?
A.To connect to the internet
B.To create modular, mountable route handlers
C.To route data to the database
D.To handle static files
Correct Answer: To create modular, mountable route handlers
Explanation:A Router instance is a complete middleware and routing system, often referred to as a 'mini-app', used to organize routes in separate files.
Incorrect! Try again.
32How do you expose a router defined in a separate file?
A.exports.router = router
B.module.exports = router
C.return router
D.export default router
Correct Answer: module.exports = router
Explanation:In CommonJS (Node.js default), you export the router instance using module.exports so it can be required in other files.
Incorrect! Try again.
33How do you mount a router module in the main app file?
A.app.add(router)
B.app.use(router)
C.app.route(router)
D.app.mount(router)
Correct Answer: app.use(router)
Explanation:app.use() is used to mount middleware functions or router instances at a specified path.
Incorrect! Try again.
34If you mount a router at '/api', and the router has a route for '/users', what is the full path?
A./users
B./api
C./api/users
D./users/api
Correct Answer: /api/users
Explanation:The paths are concatenated. The router is mounted at /api, so its internal /users route becomes /api/users.
Incorrect! Try again.
35Which library is commonly used with Express for validating incoming request data?
A.express-check
B.express-validator
C.body-check
D.node-validate
Correct Answer: express-validator
Explanation:express-validator is a set of express.js middlewares that wraps validator.js validator and sanitizer functions.
Incorrect! Try again.
36In express-validator, which function is used to validate a field in the request body?
A.checkBody()
B.body()
C.validate()
D.req.check()
Correct Answer: body()
Explanation:The body() function is used to validate fields specifically located in req.body.
Incorrect! Try again.
37What does validationResult(req) return in express-validator?
A.Boolean true/false
B.The sanitized body
C.An object containing any validation errors
D.The response object
Correct Answer: An object containing any validation errors
Explanation:validationResult(req) extracts the validation errors from a request and makes them available in a result object.
Incorrect! Try again.
38Which method in express-validator is used to check if a field is a valid email?
A.isEmail()
B.checkEmail()
C.validateEmail()
D.isValidEmail()
Correct Answer: isEmail()
Explanation:isEmail() is the standard validator function to check if a string is an email.
Incorrect! Try again.
39What is the purpose of sanitization in express-validator?
A.To reject invalid data
B.To encrypt data
C.To modify input data (e.g., trim whitespace)
D.To log data
Correct Answer: To modify input data (e.g., trim whitespace)
Explanation:Sanitization modifies the input to make it safe or standardized, such as trimming whitespace or escaping characters.
Incorrect! Try again.
40Where do you place the validation middleware in an Express route definition?
A.Inside the callback function
B.As an array of arguments before the callback
C.In the app.listen() method
D.In the package.json
Correct Answer: As an array of arguments before the callback
Explanation:Validation chains are passed as middleware arguments to the route handler before the final controller callback.
Incorrect! Try again.
41In express-validator, how do you check if the validation result contains errors?
A.errors.exist()
B.errors.isEmpty()
C.errors.hasErrors()
D.errors.length > 0
Correct Answer: errors.isEmpty()
Explanation:The result object from validationResult has an isEmpty() method that returns true if there are no errors.
Incorrect! Try again.
42Which of the following matches a route path for ANY HTTP method in Express?
A.app.any()
B.app.all()
C.app.every()
D.app.star()
Correct Answer: app.all()
Explanation:app.all() is a special routing method used to load middleware functions at a path for all HTTP request methods.
Incorrect! Try again.
43What is a 'middleware' in the context of Express?
A.Hardware drivers
B.Functions that have access to req, res, and next
C.The database layer
D.The front-end framework
Correct Answer: Functions that have access to req, res, and next
Explanation:Middleware functions are functions that have access to the request object, response object, and the next middleware function in the cycle.
Incorrect! Try again.
44What does the next argument represent in an Express middleware function?
A.The previous request
B.The database connection
C.A callback to pass control to the next middleware
D.The error object
Correct Answer: A callback to pass control to the next middleware
Explanation:Calling next() passes control to the next middleware function in the stack. If not called, the request will hang.
Incorrect! Try again.
45Which status code indicates 'Bad Request' due to validation failure?
A.200
B.400
C.404
D.503
Correct Answer: 400
Explanation:400 Bad Request is typically used when the server cannot process the request due to client error (e.g., malformed syntax, validation error).
Incorrect! Try again.
46How do you chain multiple validators on the same field in express-validator?
Explanation:Validators and sanitizers can be chained method-style on the ValidationChain object.
Incorrect! Try again.
47In a native Node server, how do you differentiate between a POST and a GET request?
A.req.type
B.req.method
C.req.action
D.req.verb
Correct Answer: req.method
Explanation:The req.method property contains the HTTP verb (e.g., 'GET', 'POST') as a string.
Incorrect! Try again.
48What is the primary advantage of using Express over the native HTTP module?
A.It allows using Java
B.It removes the need for JavaScript
C.It simplifies routing and middleware management
D.It is slower but more secure
Correct Answer: It simplifies routing and middleware management
Explanation:Express provides a higher-level abstraction that makes defining routes, handling parameters, and managing middleware significantly easier than raw Node.
Incorrect! Try again.
49Which method allows you to serve static files (images, CSS) in Express?
A.express.static()
B.express.files()
C.express.public()
D.express.assets()
Correct Answer: express.static()
Explanation:express.static(root, [options]) is a built-in middleware function in Express for serving static files.
Incorrect! Try again.
50When setting a custom response header in Express, which method is used?
A.res.addHeader()
B.res.set()
C.res.put()
D.res.config()
Correct Answer: res.set()
Explanation:res.set(field, [value]) is used to set the response HTTP header field to value.
Incorrect! Try again.
Give Feedback
Help us improve by sharing your thoughts or reporting issues.