Node.js Quizes
Node.js Quizes
Section 2:
Section 3:
4. Which of the following accurately describes the role of a web server in the client-server
model?
A. A web server sends requests to the client for data.
B. A web server renders web pages using HTML and CSS.
C. A web server hosts and serves web pages to clients upon request.
D. A web server manages client-side scripting languages like JavaScript.
5. What is the purpose of the listen() method in the context of Node.js web servers?
A. To start the server and begin accepting requests.
B. To terminate the server and stop accepting requests.
C. To specify the port number for the server.
D. To define routes and handle incoming requests.
6. When creating a Node.js server, which method is typically used to specify how the server
should respond to different URL paths?
A. setPath()
B. handleRoute()
C. onRoute()
D. createServer()
7. What happens if a blocking synchronous operation is performed in a Node.js application?
A. It will not affect the event loop, as Node.js automatically handles blocking operations.
B. It will cause the event loop to be blocked until the operation completes.
C. It will be executed asynchronously in the background.
D. It will result in an error and terminate the Node.js process.
8. In the Node.js event loop, what is the purpose of the "Poll" phase?
A. To execute I/O operations such as reading from files
B. To handle callbacks for setTimeout() and setInterval() functions
C. To perform tasks related to the network communication
D. To process callbacks registered with process.nextTick()
Section 4:
9. Which command is used to initialize a new Node.js project and create a package.json file?
A. npm init
B. npm install
C. npm start
D. npm config
17. What is the typical syntax for defining a middleware function in Express.js?
A. function middleware(req, res, next) { // middleware logic }
B. middleware(req, res, next) => { // middleware logic }
C. middleware = (req, res, next) => { // middleware logic }
D. function(req, res, next) { // middleware logic }
18.How can you export an Express Router instance for use in other modules?
A. By calling the export function and passing the router object as an argument
B. By assigning the router object to module.exports
C. By calling the module.export() function with the router object as an argument
D. By requiring the router module and calling its exported functions within other modules
20. What types of request bodies can body-parser parse by default in Express.js?
A. JSON only
B. URL-encoded form data only
C. JSON and URL-encoded form data
D. XML and plain text
Section 7:
21. In an Express.js application following the MVC pattern, where might you typically find
route definitions and request handling logic?
A. In the model layer
B. In the view layer
C. In the controller layer
D. In the middleware layer