200+ MCQ Questions On Entire CHO Topics
200+ MCQ Questions On Entire CHO Topics
3. Which layer of the OSI model does the server typically operate on? A)
Application layer
B) Transport layer
C) Network layer
D) Data Link layer
4. What protocol is commonly used for communication between client and server
on the web? A) FTP
B) HTTP
C) SMTP
D) Telnet
Answer: B) HTTP
6. What does the server do when it receives a request from a client? A) Processes
the request and returns a response
B) Ignores the request
C) Sends a new request to another server
D) Analyzes the request and forwards it to the database
7. Which HTTP method is used by the server to send data back to the client? A)
POST
B) PUT
C) GET
D) Response
Answer: C) GET
8. In Node.js, which object is used to handle HTTP requests and send responses?
A) response
B) request
C) res
D) req
Answer: B) request
3. Understanding Node.js
Answer: A) JavaScript
10. Which of the following is NOT an advantage of Node.js? A) High performance for
I/O operations
B) Uses event-driven, non-blocking I/O
C) Great for CPU-intensive tasks
D) Handles concurrent requests effectively
12. What type of architecture does Node.js use for handling multiple requests? A)
Multi-threaded
B) Single-threaded with event loop
C) Multi-process
D) Pre-emptive scheduling
13. Which of the following commands is used to install Node.js on a system? A) npm
install node
B) sudo apt install nodejs
C) install nodejs
D) npm install
14. To create a simple Node.js HTTP server, which built-in module is required? A)
express
B) http
C) mongoose
D) fs
Answer: B) http
17. Which command is used to initialize a new Node.js project and create a
package.json file? A) npm install
B) npm init
C) npm start
D) npm update
Answer: B) npm init
18. Which file contains the dependencies for a Node.js project? A) package.json
B) node_modules.json
C) server.js
D) index.html
Answer: A) package.json
19. In Node.js, how do you serve static files like images or CSS? A) Using the fs
module
B) Using the express.static() middleware
C) Using the http module
D) Using fs.readFile()
20. Which module can be used to read or write files in Node.js? A) http
B) path
C) fs
D) express
Answer: C) fs
22. What is the default port number for an Express app? A) 3000
B) 5000
C) 8080
D) 8000
Answer: A) 3000
23. Which of the following methods in Express is used to handle GET requests? A)
app.post()
B) app.get()
C) app.delete()
D) app.put()
Answer: B) app.get()
24. Which of the following is the correct syntax for defining a route parameter in
Express? A) app.get("/users/:id", ...)
B) app.get("/users/{id}", ...)
C) app.route("/users/:id", ...)
D) app.path("/users/id", ...)
8. Middleware in Express
Answer: A) app.use(express.json())
28. Which of the following is used to manage user sessions in Express? A) session
module
B) passport module
C) jsonwebtoken module
D) cookie-parser
Answer: A) session module
30. What is EJS used for in Node.js applications? A) To handle HTTP requests
B) To connect to databases
C) To generate dynamic HTML views
D) To manage sessions
Answer: B) Mongoose
Answer: B) MySQL
12. Blocking vs Non-blocking Code in Node.js
34. What is the primary difference between blocking and non-blocking code in
Node.js? A) Blocking code uses multiple threads, non-blocking code uses a single
thread
B) Blocking code cannot be executed, while non-blocking code can
C) Blocking code halts program execution, while non-blocking code allows other
tasks to run concurrently
D) Blocking code processes requests asynchronously, while non-blocking code
processes them synchronously
Answer: C) Blocking code halts program execution, while non-blocking code allows other
tasks to run concurrently
36. What is the purpose of the Multer library in Node.js? A) To parse JSON data in
HTTP requests
B) To handle file uploads in Express applications
C) To interact with MongoDB
D) To parse cookies
37. Which of the following is a correct way to configure Multer for disk storage? A)
multer.diskStorage()
B) multer.memoryStorage()
C) multer.createStorage()
D) multer.config()
Answer: A) multer.diskStorage()
38. Which of the following properties is used to specify the file destination in
Multer's disk storage configuration? A) destination
B) output
C) upload
D) filePath
Answer: A) destination
39. When handling file uploads with Multer, which event is emitted when a file is
successfully uploaded? A) error
B) file
C) upload
D) finish
Answer: B) file
Answer: A) express-session
41. Which of the following methods is used to store session data in a memory store?
A) session.memory()
B) session.set()
C) session.store()
D) session.use()
Answer: B) session.set()
42. Which of the following is true about sessions in Express.js? A) They are
automatically created when a user visits the website for the first time
B) Sessions are stored by default in a database
C) Sessions allow data to persist between requests from the same client
D) Sessions are created manually by the developer
Answer: C) Sessions allow data to persist between requests from the same client
43. Which of the following methods is used for user authentication in Express? A)
Middleware
B) passport.authenticate()
C) express-session()
D) jsonwebtoken.verify()
Answer: B) passport.authenticate()
44. What is the role of an authentication token, such as a JSON Web Token (JWT)?
A) To store user passwords securely
B) To verify the identity of a user
C) To store session data
D) To manage database queries
46. Which of the following is a common strategy for user authentication in Node.js
applications? A) Basic Authentication
B) OAuth
C) JWT (JSON Web Token)
D) All of the above
48. What does the "exp" claim in a JSON Web Token signify? A) The time the token
was created
B) The expiration time of the token
C) The issuer of the token
D) The user associated with the token
49. Which of the following statements is true regarding JWT tokens? A) They are
encrypted and stored in a database
B) They are stateless and do not require server-side storage
C) They can only be used once
D) They are stored in cookies by default
52. Which of the following is true about Client-Side Rendering (CSR)? A) It provides
better SEO out-of-the-box
B) It requires an initial server request to fetch HTML, CSS, and JavaScript
C) It is typically used in static websites
D) It renders HTML on the server before sending it to the client
Answer: B) It requires an initial server request to fetch HTML, CSS, and JavaScript
Answer: B) Next.js
55. Which of the following is true about EJS templates in Node.js? A) EJS does not
support embedding JavaScript inside HTML
B) EJS allows you to include partial views like headers or footers in templates
C) EJS templates cannot receive dynamic data
D) EJS is only used for client-side rendering
Answer: B) EJS allows you to include partial views like headers or footers in templates
56. How do you pass data from an Express route to an EJS template? A) Using
res.send()
B) Using res.render() with a data object
C) Using res.json()
D) Using app.use()
57. What is the purpose of partials in EJS? A) To render entire HTML pages
B) To create reusable components (e.g., header, footer)
C) To store dynamic data
D) To define new routes
Answer: C) MongoDB
Answer: A) mongoose
62. Which of the following is required to create a connection with MongoDB using
Mongoose? A) mongoose.connect(<url>, <options>)
B) mongoose.db(<url>, <options>)
C) mongoose.connect()
D) mongoose.connectToDB(<url>)
Answer: B) Row
64. Which of the following is the correct way to handle exceptions in Node.js? A)
Using try-catch blocks
B) Using catch function
C) Using throw without a try block
D) Node.js does not support error handling
65. What does the uncaughtException event in Node.js handle? A) Errors during the
event loop
B) Errors that occur asynchronously
C) Errors that are not caught by try-catch blocks
D) Syntax errors in the code
Answer: A) next()
67. What is the purpose of the next() function in Express? A) To terminate the
request
B) To invoke the next middleware function in the stack
C) To throw an error
D) To send a response to the client
70. Which of the following is true about Promises in JavaScript? A) They are used to
handle synchronous operations
B) They allow chaining of multiple asynchronous operations
C) They make asynchronous code execute sequentially
D) They do not return any value
71. What does the async keyword in front of a function indicate? A) The function is
executed synchronously
B) The function will always return a promise
C) The function will return a generator function
D) The function will run in the background
72. What does the await keyword do in JavaScript? A) Pauses the execution of the
function until a Promise is resolved
B) Executes a function asynchronously
C) Makes a function synchronous
D) Returns a resolved promise
Answer: A) Pauses the execution of the function until a Promise is resolved
73. Which HTTP method is used to retrieve information from a server in Express?
A) POST
B) PUT
C) GET
D) DELETE
Answer: C) GET
74. What is the purpose of route parameters in Express? A) To define different paths
for each route
B) To accept dynamic values in routes
C) To handle HTTP request methods
D) To generate the response from the server
Answer: B) req.query
Answer: A) express.static()
81. How do you set the public directory for serving static files in Express? A)
app.use(express.static('public'))
B) app.static('public')
C) express.static('/public')
D) app.serve('public')
Answer: A) app.use(express.static('public'))
82. Which of the following files can be served as static files in Express? A) HTML,
CSS, JavaScript files
B) Images (JPG, PNG, GIF)
C) Fonts (WOFF, TTF)
D) All of the above
Answer: A) express.json()
85. Which of the following is a popular SQL database used with Node.js? A)
MongoDB
B) MySQL
C) Redis
D) Cassandra
Answer: B) MySQL
86. Which Node.js ORM is commonly used to interact with relational databases like
MySQL and PostgreSQL? A) Sequelize
B) Mongoose
C) Knex.js
D) TypeORM
Answer: A) Sequelize
87. Which of the following is a key feature of NoSQL databases like MongoDB? A)
They are highly structured
B) They store data in tables
C) They are more flexible in terms of schema design
D) They use SQL to query data
88. What is the correct method to connect to MongoDB using Mongoose in Node.js?
A) mongoose.db.connect()
B) mongoose.connect('mongodb://localhost/dbname')
C) mongoose.connectToDB()
D) mongoose.startConnection()
Answer: B) mongoose.connect('mongodb://localhost/dbname')
89. Which of the following is the correct way to define a schema in Mongoose? A)
mongoose.Schema({name: String, age: Number})
B) mongoose.Schema({name: "String", age: 25})
C) mongoose.Schema("users", {name, age})
D) mongoose.createSchema({name: "String", age: "Number"})
90. What method would you use in Mongoose to find all documents in a collection?
A) Model.get()
B) Model.find()
C) Model.query()
D) Model.fetch()
Answer: B) Model.find()
91. Which of the following is the correct way to create a JWT token in Node.js using
jsonwebtoken? A) jwt.createToken()
B) jwt.encode()
C) jwt.sign(payload, secret)
D) jwt.generateToken()
Answer: A) jwt.verify()
This brings us closer to completing the desired collection of questions across all the key
topics. If you would like more questions for any specific sections, feel free to let me know! I
can keep adding more until we hit the target of 200 questions.
4o mini
You said:
30. Client-Side vs Server-Side Rendering (CSR vs SSR)
Answer: A) Slower initial page load times due to large JavaScript files
96. In which situation would Server-Side Rendering (SSR) be preferred over Client-
Side Rendering (CSR)? A) When SEO and faster content rendering are critical
B) When the application is purely dynamic and does not need SEO
C) When client-side JavaScript is not supported
D) When the application is highly interactive
97. Which of the following tools or frameworks can be used to implement Server-
Side Rendering (SSR) with React? A) React Native
B) Next.js
C) Angular Universal
D) Vue CLI
Answer: B) Next.js
98. What is the primary purpose of a template engine like EJS in a Node.js
application? A) To handle database queries
B) To render dynamic HTML views with embedded JavaScript
C) To manage routing logic
D) To manage user authentication
99. Which of the following is a feature of the EJS template engine? A) Supports two-
way data binding
B) Can directly manipulate the DOM in the browser
C) Allows embedding of JavaScript expressions inside HTML
D) Only works with static HTML files
100. How do you render a template with data in Express using EJS? A)
res.sendFile()
B) res.render('template', data)
C) res.write(data)
D) res.send(data)
102. Which is the correct syntax for including a partial view in an EJS
template? A) <%- include 'header' %>
B) <%= include 'header' %>
C) <div> include 'header' </div>
D) {{ include 'header' }}
Answer: C) MongoDB
104. What is the default data format used by MongoDB for storing data? A)
JSON
B) BSON (Binary JSON)
C) XML
D) CSV
Answer: A) mongoose
Answer: A) Model.findById()
108. Which of the following is a key feature of SQL databases like MySQL? A)
Schema-less design
B) Horizontal scaling
C) Tables with rows and columns
D) Document-oriented structure
Answer: B) MySQL
Answer: C) express-session
112. Which of the following is responsible for determining what actions a user
can perform within an application? A) Authentication
B) Authorization
C) Session management
D) Cookie parsing
Answer: B) Authorization
113. What is the role of JWT (JSON Web Token) in an authentication system?
A) It stores session data on the server
B) It encrypts the user password
C) It is used to verify the user's identity and grant access to protected routes
D) It handles database queries
Answer: C) It is used to verify the user's identity and grant access to protected routes
114. Which of the following is the correct method to generate a JWT token in
Node.js using the jsonwebtoken package? A) jwt.create()
B) jwt.sign(payload, secret)
C) jwt.encode()
D) jwt.newToken()
Answer: B) To modify the request and response objects or end the request-response cycle
Answer: A) express.json()
Answer: B) multer
121. Which storage engine in Multer is used for storing files on disk? A)
memoryStorage
B) diskStorage
C) fileStorage
D) uploadStorage
Answer: B) diskStorage
122. Which of the following is the correct way to define a file upload limit
using Multer? A) upload.limit(10MB)
B) upload.size('10MB')
C) upload.single('file').limit(10MB)
D) upload.single('file').maxSize(10)
Answer: A) upload.limit(10MB)
123. Which of the following is used to handle multiple HTTP methods (e.g.,
GET, POST) for the same route in Express? A) app.all()
B) app.use()
C) app.route()
D) app.method()
Answer: C) app.route()
124. What does the req.body object in Express represent? A) The query
parameters in the request URL
B) The data sent in a POST or PUT request
C) The headers of the request
D) The path of the requested URL
125. Which of the following is the correct way to redirect a user to another
route in Express? A) res.redirect('/newpath')
B) res.sendRedirect('/newpath')
C) res.moveTo('/newpath')
D) res.location('/newpath')
Answer: A) res.redirect('/newpath')
126. In Express, what does the res.json() method do? A) Sends a plain text
response
B) Sends a JSON response to the client
C) Converts a JavaScript object into a JSON string
D) Sends an HTML response
Answer: A) express.static()
Answer: A) .catch()
Answer: A) Write synchronous code that waits for asynchronous operations to complete
131. Which of the following functions would you use in Node.js to read a file
asynchronously? A) fs.readFileSync()
B) fs.readFile()
C) fs.read()
D) fs.readAsync()
Answer: B) fs.readFile()
133. Which of the following is the best way to store user credentials securely in
a Node.js application? A) Storing passwords in plain text in the database
B) Using bcrypt to hash passwords before storing them
C) Storing passwords in cookies
D) Storing passwords in a session
134. Which Node.js package is commonly used for authenticating users via a
social login (Google, Facebook)? A) passport
B) jwt-simple
C) cookie-parser
D) express-session
Answer: A) passport
135. What is the main purpose of JWT (JSON Web Token) in user
authentication? A) To send the user's password over the network
B) To generate a session ID that is stored on the server
C) To securely transfer information between parties
D) To hash the user's password for storage
136. How can you ensure that a route is protected and only accessible to
authenticated users in Express? A) By using app.use() middleware to check for a
valid session or JWT token
B) By calling next() in every route handler
C) By checking the IP address of the client
D) By enforcing CORS (Cross-Origin Resource Sharing)
Answer: A) By using app.use() middleware to check for a valid session or JWT token
137. Which of the following is the correct way to create a hashed password
using bcrypt in Node.js? A) bcrypt.hashSync('password', 10)
B) bcrypt.hash('password', 10)
C) bcrypt.encrypt('password')
D) bcrypt.encryptSync('password', 10)
138. In Multer, which of the following is used to define where files will be
stored? A) storage
B) destination
C) uploadTo
D) store
Answer: A) storage
139. Which of the following is a valid method to specify limits on file size in
Multer? A) upload.size(10MB)
B) upload.fileSize(10MB)
C) upload.limit({ fileSize: 10MB })
D) upload.setSize(10MB)
Answer: A) upload.single('file')
141. Which property in the Multer request object holds the uploaded file
information? A) req.body
B) req.files
C) req.file
D) req.data
Answer: C) req.file
142. Which of the following is the correct method to configure the Multer
storage engine for saving files to disk? A) storage: multer.diskStorage()
B) storage: multer.memoryStorage()
C) storage: multer.createStorage()
D) storage: multer.config()
143. Which of the following commands initializes a new Node.js project and
creates a package.json file? A) npm start
B) npm init
C) npm install
D) npm run
144. How can you install a specific version of a package using npm? A) npm
install package@<version>
B) npm install package<version>
C) npm install -version <version>
D) npm install <version>
147. Which command is used to uninstall a package from your Node.js project
using npm? A) npm uninstall <package>
B) npm remove <package>
C) npm delete <package>
D) npm uninstall <package> --global
148. In a RESTful API, what does the HTTP GET method typically do? A)
Submits data to be processed
B) Retrieves data from the server
C) Deletes a resource
D) Updates a resource
Answer: A) app.put()
151. Which of the following is the correct way to handle errors in Express? A)
By using a try-catch block in each route
B) By using next() to pass errors to the error-handling middleware
C) By calling res.error()
D) By logging errors to the console
155. In Express, how do you respond to the client when an error occurs? A)
res.sendError()
B) res.status(500).send('Internal Server Error')
C) res.sendMessage('Error')
D) res.error()
156. Which of the following modules is part of the Node.js core and allows you
to handle HTTP requests and responses? A) express
B) http
C) mongoose
D) socket.io
Answer: B) http
158. What is the default behavior of the Node.js event loop? A) It processes
synchronous operations first and asynchronous operations second
B) It processes asynchronous operations first and synchronous operations second
C) It processes both asynchronously
D) It only processes synchronous operations
Answer: B) Asynchronous
Answer: A) mongoose.connect()
Answer: A) mongoose.model()
163. Which of the following is the correct way to create a new document using
Mongoose? A) Model.save()
B) Model.create()
C) Model.insert()
D) Model.new()
Answer: B) Model.create()
Answer: D) Model.updateOne()
166. Which of the following JWT sections contains the claims or data about
the user? A) Header
B) Payload
C) Signature
D) Header and Signature
Answer: B) Payload
167. Which of the following is a typical use case for JSON Web Tokens
(JWT)? A) Storing the user's password securely
B) Sending authentication credentials between client and server
C) Encrypting sensitive data in the database
D) Creating session cookies for a client
168. Which of the following HTTP headers is typically used to send a JWT
from a client to a server? A) Authorization
B) Content-Type
C) X-Auth-Token
D) Cookie
Answer: A) Authorization
169. What does JWT's "HS256" algorithm refer to? A) The method used to sign
the token
B) The encryption standard used in JWT
C) The number of claims in the token
D) The length of the JWT token
170. How would you decode a JWT token in Node.js using the jsonwebtoken
package? A) jwt.verify(token, secret)
B) jwt.decode(token)
C) jwt.decode(token, secret)
D) jwt.parse(token)
Answer: B) jwt.decode(token)
171. Which of the following middleware is used to serve static files in Express?
A) express.static()
B) express.serveStatic()
C) express.fileServe()
D) express.sendFile()
Answer: A) express.static()
172. Which of the following is the correct way to serve static files from the
"public" directory in Express? A) app.use(express.static('public'))
B) app.use(express.fileServe('public'))
C) app.static('public')
D) app.serve('public')
Answer: A) app.use(express.static('public'))
173. Which Express method would you use to send a static HTML file in
response to a GET request? A) res.sendFile()
B) res.send()
C) res.render()
D) res.view()
Answer: A) res.sendFile()
174. Which of the following is the correct way to define a route handler for a
GET request in Express? A) app.route('/path').get()
B) app.get('/path')
C) app.use('/path', 'get')
D) app.handle('/path', 'GET')
Answer: B) app.get('/path')
Answer: B) It is used to declare middleware functions that run for every incoming request
Answer: B) It passes the request to the next middleware or route handler in the stack
177. Which of the following is used to handle route parameters in Express? A)
req.body
B) req.query
C) req.params
D) req.path
Answer: C) req.params
178. What is the primary difference between client-side rendering (CSR) and
server-side rendering (SSR)? A) CSR sends HTML content from the server to the
client, while SSR sends JavaScript content
B) CSR executes JavaScript on the client-side to render the content, while SSR
generates HTML on the server and sends it to the client
C) CSR is only possible in React applications, while SSR is used in Vue.js
applications
D) CSR uses fewer resources on the server, while SSR uses fewer resources on the
client
Answer: B) CSR executes JavaScript on the client-side to render the content, while SSR
generates HTML on the server and sends it to the client
179. Which of the following is a key advantage of SSR over CSR? A) SSR tends
to have better SEO performance since the HTML content is fully rendered on the
server
B) SSR has faster page loading times because the server sends raw JavaScript
C) SSR is less resource-intensive for the client compared to CSR
D) SSR works only with JavaScript frameworks like React
Answer: A) SSR tends to have better SEO performance since the HTML content is fully
rendered on the server
180. Which of the following is a popular template engine used with Express.js?
A) Pug (formerly Jade)
B) Handlebars
C) EJS
D) All of the above
181. Which of the following is the correct way to set the view engine to EJS in
Express? A) app.set('view', 'ejs')
B) app.set('view engine', 'ejs')
C) app.set('viewTemplate', 'ejs')
D) app.use('ejs')
Answer: B) app.set('view engine', 'ejs')
182. Which EJS syntax is used to include another EJS template inside the
current template? A) <% include file.ejs %>
B) <% import file.ejs %>
C) <% require('file.ejs') %>
D) <% include('file.ejs') %>
183. What does the EJS <%= %> tag do? A) It outputs raw JavaScript code
B) It outputs the result of a JavaScript expression to the HTML
C) It is used to include a template
D) It marks a section of HTML to be ignored
184. How can you pass data from a route handler to an EJS view in Express?
A) res.send(data)
B) res.render('view', { data })
C) res.json(data)
D) res.view('view', data)
Answer: A) express-session
186. Which of the following is the correct way to initialize session middleware
in an Express app? A) app.use(express.session())
B) app.use(session())
C) app.use(session({ secret: 'your-secret-key' }))
D) app.use(cookieParser())
Answer: A) req.session.destroy()
Answer: A) It parses cookies in the request and makes them accessible via req.cookies
190. Which Node.js module is used for interacting with the file system? A) fs
B) fileSystem
C) path
D) file-system
Answer: A) fs
191. Which of the following is the correct method to read a file asynchronously
in Node.js? A) fs.readFileSync()
B) fs.readFile()
C) fs.read()
D) fs.open()
Answer: B) fs.readFile()
Answer: B) fs.writeFile()
193. Which method in the fs module would you use to check if a file exists? A)
fs.existsSync()
B) fs.checkFile()
C) fs.isExist()
D) fs.exists()
Answer: A) fs.existsSync()
194. How would you stream a large file in Node.js to avoid blocking the event
loop? A) Using fs.readFile()
B) Using fs.createReadStream()
C) Using fs.writeFileSync()
D) Using fs.appendFile()
Answer: A) Model.find()
Answer: A) mongoose.connect('mongodb://localhost/mydb')
198. What is the purpose of the Schema in Mongoose? A) It defines the structure
of the MongoDB documents for a specific collection
B) It is used to create queries to find documents
C) It maps the documents to a specific view in an application
D) It stores the database connection information
Answer: A) It defines the structure of the MongoDB documents for a specific collection
Answer: A) Model.save()
201. Which of the following is a Node.js tool that helps with debugging and
performance profiling? A) node-inspect
B) node-debugger
C) node-profile
D) node-track
Answer: A) node-inspect
202. What is the primary reason Node.js is known for being efficient in
handling I/O operations? A) Node.js runs on a single thread using non-blocking I/O
operations
B) Node.js executes all tasks synchronously
C) Node.js performs caching of database queries
D) Node.js uses a multi-threaded event loop
205. Which module is commonly used for handling file uploads in Node.js? A)
multer
B) formidable
C) busboy
D) All of the above
Answer: A) diskStorage()
208. What is the role of req.file in the file upload process using multer? A) It
contains information about the uploaded file, such as the file name and path
B) It contains the entire file content in the buffer format
C) It is a method used to retrieve the uploaded file
D) It contains the MIME type of the uploaded file
Answer: A) It contains information about the uploaded file, such as the file name and path
209. What is the maximum file size allowed by multer by default? A) 10MB
B) 1MB
C) Unlimited
D) 2MB
210. Which Node.js debugger tool is built into Node.js and can be used for
interactive debugging? A) node-inspect
B) node-debug
C) node-logger
D) node-debugger
Answer: A) node-inspect
213. In Node.js, which tool can be used to inspect memory leaks and
performance issues? A) heapdump
B) node-inspect
C) v8-profiler
D) Both A and C
214. Which of the following can you use to get stack traces in Node.js to help
debug asynchronous code? A) process.on('uncaughtException', callback)
B) console.trace()
C) node-inspect
D) setTimeout()
Answer: B) console.trace()
216. Which package is commonly used to secure HTTP headers and prevent
common attacks in Node.js applications? A) helmet
B) cors
C) express-rate-limit
D) body-parser
Answer: A) helmet
218. Which of the following best describes SQL Injection attacks? A) Attacks
that modify the client-side UI of a web page
B) Attacks that allow an attacker to inject malicious code into the database
C) Attacks that prevent the server from sending responses
D) Attacks that exploit client-side scripts for data theft
Answer: B) Attacks that allow an attacker to inject malicious code into the database
219. How can you prevent SQL Injection attacks in a Node.js application? A)
Use prepared statements or parameterized queries
B) Sanitize and validate user input
C) Avoid concatenating SQL queries directly with user data
D) All of the above
220. What is the role of the cluster module in Node.js? A) It handles multiple
threads of execution on different machines
B) It allows Node.js to be run on multiple CPU cores by creating child processes
C) It manages database connections for Node.js applications
D) It helps to manage in-memory caches
Answer: B) It allows Node.js to be run on multiple CPU cores by creating child processes
221. Which of the following statements about the async and await keywords in
Node.js is correct? A) async makes a function return a Promise, and await pauses
the execution until the Promise resolves
B) async pauses the execution, and await returns a Promise
C) Both async and await are used to handle callbacks
D) async and await are not supported in Node.js
Answer: A) async makes a function return a Promise, and await pauses the execution until
the Promise resolves
Answer: B) It resolves when all the promises in the array are fulfilled
223. Which of the following is the correct way to handle an error in an async
function in Node.js? A) Using a try-catch block
B) Using the .catch() method on the promise
C) Using the Promise.reject() method
D) Both A and B
224. Which of the following modules is commonly used to work with streams
in Node.js? A) stream
B) http
C) express
D) socket.io
Answer: A) stream
Answer: A) It compresses responses to reduce the size of the data sent to the client
227. Which of the following is a common method for managing static assets in
Express for better performance? A) Use express.static() middleware
B) Store static files in the database
C) Compress static files using Gzip
D) Serve static files directly from the client
Answer: B) It enables the use of secure cookies and tracks the originating IP address when
the app is behind a proxy
229. Which of the following can help improve the performance of an Express
application? A) Use app.use() for common middleware
B) Minimize the number of middleware functions executed per request
C) Use asynchronous handlers for I/O-bound operations
D) All of the above