Node JS MCQs With Answer
Node JS MCQs With Answer
What is Node.js?
O
a) A web browser
b) A server-side JavaScript runtime
N
c) A database
d) A markup language
4. Which of the following modules is commonly used for handling file operations in
Node.js?
a) fs
b) http
c) net
d) path
Answer: a) fs
O
Answer: a) Express
N
8. What is the role of the process object in Node.js?
a) Handling file operations
b) Managing network requests
H
c) Controlling the Node.js process
d) Parsing JSON data
Answer: b) Yarn
O
14. What is the role of the Buffer class in Node.js?
a) Handling file operations
N
b) Reading user input
c) Storing binary data
H
d) Controlling network requests
Answer: b) http
16. How can you install a specific version of a Node.js package using npm?
a) npm install package@version
AR
18. Which of the following is a valid way to import the fs module in Node.js?
a) import fs from 'fs';
b) const fs = require('fs');
c) include fs from 'fs';
d) const fs = import('fs');
O
Answer: d) Using the event-driven model
N
a) To parse JSON data in the request body
b) To handle HTTP headers
H
c) To encrypt data
d) To set response status codes
C
Answer: a) To parse JSON data in the request body
TE
21. Which of the following is the correct way to install Express.js using npm?
Answer: c) PUT
24. What is the role of the dotenv module in a Node.js application?
a) To handle environment variables
b) To encrypt data
c) To parse JSON data
d) To create a server
25. How can you handle cross-origin resource sharing (CORS) in an Express.js application?
a) By using the cross-origin middleware
b) By setting the Access-Control-Allow-Origin header
c) By using the cors middleware
O
d) By configuring the server to allow all origins
N
Answer: c) By using the `cors` middleware
H
a) To create child threads
b) To spawn child processes
c) To manage child modules
d) To handle child exceptions
C
TE
Answer: b) To spawn child processes
28. Which of the following is a templating engine commonly used with Express.js?
a) Pug
b) Jade
c) EJS
d) Handlebars
Answer: c) EJS
29. How do you set up a basic HTTP server in Node.js without using any external
framework?
a) Using the http.createServer method
b) Using the express module
c) Using the server module
d) Using the http.server method
Answer: a) Using the `http.createServer` method
O
c) To handle HTTP requests
d) To encrypt data
N
Answer: b) To connect to a MongoDB database
H
32. Which of the following is true about the event-driven model in Node.js?
a) It uses multiple threads to handle events
b) It is synchronous in nature
C
c) It is based on the publish-subscribe pattern
d) It does not support events
TE
37. Which of the following modules can be used for handling asynchronous operations in
Node.js?
O
a) async
b) sync
c) await
N
d) defer
H
Answer: a) async
40. Which of the following is a built-in module in Node.js for handling URL-related tasks?
a) url
b) path
c) querystring
d) request
Answer: a) url
Answer: d) process.exit();
O
Answer: b) To configure middleware
N
43. Which module can be used for creating a secure HTTPS server in Node.js?
a) https
H
b) secure
c) ssl
d) tls
C
Answer: a) https
TE
45. How do you install a specific version of Node.js using nvm (Node Version Manager)?
a) nvm install node@version
b) nvm install version
c) nvm use version
d) nvm install node/version
Answer: b) mocha
47. What is the purpose of the pm2 module in Node.js?
a) To manage Node.js processes
b) To create middleware functions
c) To handle HTTP requests
d) To serve static files
O
d) To encrypt data
N
Answer: c) To process multipart/form-data for file uploads
© Copyright Aryatechno. All Rights Reserved. Written tutorials and materials by Aryatechno
H
C
TE
YA
AR