0% found this document useful (0 votes)
5 views

nodejs-output_edited

The document contains a series of questions and answers related to Node.js, covering various topics such as its usage, core modules, asynchronous operations, and best practices. Each question includes multiple-choice options with the correct answer indicated. The content serves as a quiz or study guide for individuals looking to test their knowledge of Node.js.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

nodejs-output_edited

The document contains a series of questions and answers related to Node.js, covering various topics such as its usage, core modules, asynchronous operations, and best practices. Each question includes multiple-choice options with the correct answer indicated. The content serves as a quiz or study guide for individuals looking to test their knowledge of Node.js.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 107

node js

QUESTION 1
What is Node.js primarily used for?

A. Frontend Development
B. Backend Development
C. Database Management
D. Game Development

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 2
Which language does Node.js use?

A. Python
B. Java
C. JavaScript
D. Ruby

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 3
Node.js is based on which runtime environment?

A. V8
B. Chakra
C. SpiderMonkey
D. Rhino

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 4
How does Node.js handle I/O operations?

A. Synchronous
B. Asynchronous
C. Concurrent
D. Serial
Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 5
Which keyword is used to import modules in Node.js?

A. import
B. include
C. require
D. fetch

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 6
What does module.exports do?

A. Exports functions to other modules


B. Initializes the module
C. Imports other modules
D. Sets up a new module

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 7
Which module is used for creating an HTTP server?

A. http
B. server
C. os
D. express

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 8
What does NPM stand for?

A. Node Program Management


B. Node Package Manager
C. Network Program Manager
D. Node Processing Module

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 9
How do you install a package globally using NPM?

A. npm install <package>


B. npm install -g <package>
C. npm add <package>
D. npm -global install <package>

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 10
What file contains dependencies for a Node.js project?

A. config.json
B. npm.json
C. package.json
D. dependencies.json

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 11
Which function executes code after a specified delay?

A. setTimeout
B. setInterval
C. setDelay
D. asyncFunction

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
QUESTION 12
Which Node.js module provides utilities for working with asynchronous callbacks?

A. fs
B. async
C. util
D. callbacks

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 13
Node.js relies on which architecture to handle events?

A. Procedural
B. Synchronous
C. Event-driven
D. Multi-threaded

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 14
Which module is central to event handling in Node.js?

A. fs
B. events
C. http
D. emitter

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 15
What is Express.js primarily used for in Node.js?

A. Frontend styling
B. Data modeling
C. Server-side framework
D. Testing

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 16
What function is used to create a route in Express.js?

A. expressRoute()
B. route()
C. app.route()
D. app.get()

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 17
Which of the following is a best practice in Node.js?

A. Blocking I/O operations


B. Using synchronous functions
C. Using asynchronous patterns
D. Ignoring error handling

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 18
What type of logging is recommended for production?

A. console.log
B. Verbose logging
C. Structured logging
D. Debug logging

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 19
Which protocol does WebSocket use?

A. HTTP
B. HTTPS
C. ws://
D. socket.io

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 20
What is the primary purpose of WebSocket?

A. Database connections
B. Real-time, two-way communication
C. File transfer
D. Video streaming

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 21
In Express.js, middleware functions can modify the:

A. Request and response objects


B. Database schema
C. Network protocols
D. HTML templates

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 22
What is the typical position of middleware in Express routes?

A. Before the route handlers


B. After the route handlers
C. Middleware is independent of route handlers
D. Middleware is only used with errors

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
QUESTION 23
Which method is used to read data in chunks in Node.js?

A. read()
B. pipe()
C. chunk()
D. stream()

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 24
Which type of stream is used to read data?

A. Writable
B. Readable
C. Duplex
D. Transform

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 25
Which function is used to read a file synchronously in Node.js?

A. fs.read()
B. fs.readSync()
C. fs.readFileSync()
D. fs.syncRead()

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 26
How do you write data to a file in an asynchronous way?

A. fs.writeFileSync
B. fs.appendFile
C. fs.writeFile
D. fs.writeAsync

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 27
What does a Promise represent?

A. A synchronous function
B. A completed task
C. An eventual result of an asynchronous operation
D. A user input

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 28
What does the await keyword do in an async function?

A. Pauses execution until the Promise is resolved


B. Rejects a Promise
C. Schedules a callback
D. Cancels an async function

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 29
What is the purpose of the Event Loop in Node.js?

A. Manages synchronous code


B. Handles asynchronous operations
C. Loads modules
D. Manages HTTP requests

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 30
The Event Loop executes which type of operations first?

A. Network I/O
B. Timers
C. Microtasks
D. File operations

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 31
Which of the following is a Node.js feature?

A. Blocking I/O
B. Single-threaded event loop
C. Multi-threaded architecture
D. Client-side scripting

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 32
What kind of applications is Node.js well-suited for?

A. CPU-intensive applications
B. I/O-bound applications
C. GUI-based applications
D. Desktop applications

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 33
Which built-in method is used to output logs to the console in Node.js?

A. log()
B. console()
C. output()
D. console.log()

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:
Modules and Require (Extended)
QUESTION 34
Which of the following is NOT a core module in Node.js?

A. os
B. http
C. express
D. path

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 35
How would you import a custom module located in the same directory?

A. require('./module')
B. require('module')
C. import('module')
D. module.exports('./module')

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 36
How do you export multiple functions from a Node.js module?

A. Use exports object with named properties


B. Use module.exports with named properties
C. Use return statement
D. Import both functions in a single file

Correct Answer: AB
Section: (none)
Explanation

Explanation/Reference:

QUESTION 37
Which command lists globally installed npm packages?

A. npm list
B. npm list -g
C. npm -global list
D. npm show global

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 38
What does the --save flag do when installing an npm package?

A. Installs the package locally


B. Saves the package as a devDependency
C. Adds the package to the dependencies field in package.json
D. Deletes the package from node_modules

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 39
How do you update npm itself to the latest version?

A. npm update npm


B. npm install npm -g
C. npm upgrade
D. npm self-update

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 40
What does the callback function in asynchronous functions prevent?

A. Race conditions
B. Deadlocks
C. Blocking code execution
D. High memory usage

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 41
Which of the following can handle asynchronous operations in Node.js?

A. Events
B. Promises
C. async/await
D. All of the above

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 42
What is a callback hell?

A. A situation with nested callbacks, making code unreadable


B. Errors that occur in callback functions
C. A place in memory where callbacks are stored
D. When a callback is executed multiple times

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 43
How do you listen to events in Node.js?

A. By calling event.on()
B. By calling event.listen()
C. By using event.subscribe()
D. By creating a new EventListener()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 44
Which method is used to emit an event in Node.js?

A. emit()
B. on()
C. trigger()
D. call()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
QUESTION 45
What is a key advantage of an event-driven model in Node.js?

A. It handles synchronous code efficiently


B. It improves memory management
C. It scales well for handling multiple I/O requests
D. It requires no error handling

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 46
What is the default port used by Express applications?

A. 80
B. 443
C. 3000
D. 5000

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 47
Which middleware is commonly used for parsing JSON in Express?

A. body-parser
B. json-parser
C. cookie-parser
D. express-parser

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 48
How do you handle errors globally in Express?

A. Using error-handling middleware


B. Catching errors in every route
C. Using try-catch in each route
D. By ignoring error codes

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 49
What is a recommended way to structure a Node.js project?

A. Keep all code in one file


B. Use modularized code with separate files for routes, models, etc.
C. Combine frontend and backend code
D. Write all functions globally

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 50
What should you avoid when working with sensitive data in Node.js?

A. Using environment variables


B. Hardcoding sensitive information
C. Using third-party libraries
D. Minifying code

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 51
Why is it recommended to use async/await in Node.js applications?

A. It improves error handling and readability


B. It makes code synchronous
C. It blocks the Event Loop
D. It executes code faster

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 52
Which library is commonly used for WebSocket communication in Node.js?

A. http
B. ws
C. socket.io
D. net

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 53
What method initiates a WebSocket connection?

A. ws.start()
B. ws.connect()
C. new WebSocket()
D. ws.open()

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 54
What does WebSocket enable for real-time applications?

A. File upload
B. Bi-directional communication
C. Asynchronous file read
D. HTTP-based communication

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 55
What is the role of next() in Express middleware?

A. Ends the request-response cycle


B. Passes control to the next middleware
C. Caches the response
D. Initializes the app

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
QUESTION 56
In which order does Express execute middleware functions?

A. Alphabetical order
B. Reverse order of declaration
C. Order of declaration
D. Random order

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 57
How can you pipe data from a readable stream to a writable stream in Node.js?

A. readable.pipe(writable)
B. writable.pipe(readable)
C. readable.write(writable)
D. writable.read(readable)

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 58
Which event is emitted when a readable stream ends?

A. close
B. end
C. finish
D. stop

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 59
Which method is used to check if a file exists in Node.js?

A. fs.existsSync()
B. fs.fileExists()
C. fs.check()
D. fs.accessSync()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 60
Which fs method is used to delete a file asynchronously?

A. fs.delete()
B. fs.remove()
C. fs.unlink()
D. fs.rm()

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 61
What does the then() method of a Promise do?

A. Chains asynchronous operations


B. Returns a resolved Promise
C. Handles synchronous code
D. Throws an error

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 62
How do you handle errors in a Promise chain?

A. By using a second argument in then()


B. By using a .catch() method
C. By ignoring them
D. By using await

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 63
What kind of tasks does the Event Loop prioritize in Node.js?

A. Network requests
B. Timers
C. Microtasks
D. File I/O

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 64
What are the phases of the Event Loop?

A. Timers, I/O callbacks, close callbacks, poll, check, and immediate


B. Main phase and secondary phase
C. Setup and teardown
D. Input phase and output phase

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 65
Which of the following describes Node.js's single-threaded model?

A. All code executes on a single thread, blocking I/O


B. Node.js uses multiple threads for I/O and executes code in parallel
C. Node.js uses a single thread but handles I/O asynchronously
D. Node.js is only capable of executing one process at a time

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 66
Which of the following is true about Node.js?

A. Node.js is only for web servers


B. Node.js uses an event-driven, non-blocking I/O model
C. Node.js only works on Linux systems
D. Node.js is a framework

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
QUESTION 67
Which built-in Node.js module allows you to work with the operating system?

A. fs
B. os
C. http
D. path

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 68
Which module allows you to parse JSON files in Node.js?

A. json-parser
B. json
C. fs
D. path

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 69
How do you access the version of a Node.js module from within your code?

A. module.version
B. require('module').version
C. module.info()
D. node.getVersion()

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 70
How can you use a Node.js module without installing it?

A. By using require() and specifying a path to the module


B. By downloading the module manually
C. By specifying global keyword
D. By creating a symbolic link

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 71
Which command is used to initialize a new Node.js project and generate a package.json file?

A. npm create
B. npm init
C. npm start
D. npm install

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 72
How would you uninstall a package globally using NPM?

A. npm uninstall <package> -g


B. npm remove <package> --global
C. npm delete -g <package>
D. npm remove --global <package>

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 73
Which command can you use to check for outdated npm packages?

A. npm outdated
B. npm check
C. npm list --outdated
D. npm update --outdated

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 74
Which function is used to schedule a one-time delay for executing code in Node.js?

A. setTimeout()
B. setInterval()
C. setDelay()
D. asyncWait()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 75
What happens if a callback function is not passed to an asynchronous function?

A. The function will execute synchronously


B. The callback is ignored and the function continues executing
C. The function throws an error
D. The program stops running

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 76
Which method in Node.js can handle multiple asynchronous operations concurrently?

A. async.series()
B. async.parallel()
C. Promise.all()
D. async.all()

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 77
How do you define an event emitter in Node.js?

A. new EventEmitter()
B. events.createEmitter()
C. Emitter.create()
D. new EventListener()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
QUESTION 78
What will happen if an event is emitted but no listeners are attached in Node.js?

A. Nothing happens
B. The event will be lost
C. Node.js throws an error
D. Node.js will create a default listener

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 79
How do you remove a listener from an event emitter?

A. emitter.removeListener(event, listener)
B. emitter.off(event, listener)
C. emitter.remove(event)
D. emitter.remove(listener)

Correct Answer: AB
Section: (none)
Explanation

Explanation/Reference:

QUESTION 80
Which method is used to serve static files in Express.js?

A. app.use(express.static())
B. express.serveStatic()
C. app.serveStatic()
D. express.static()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 81
Which HTTP method does Express.js use to handle POST requests?

A. app.get()
B. app.post()
C. app.put()
D. app.delete()

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 82
Which of the following is correct for handling errors in Express?

A. app.error()
B. app.handleError()
C. app.use() with a four-argument function
D. express.use()

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 83
What should be the main concern when handling errors in Node.js?

A. Ignore errors for faster execution


B. Propagate errors to higher-level handlers for logging and reporting
C. Log errors without stopping execution
D. Catch and suppress errors to prevent crashes

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 84
Which tool is commonly used for testing Node.js applications?

A. Jest
B. Mocha
C. Jasmine
D. All of the above

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 85
Why is using environment variables for configuration considered a best practice?

A. It allows easier switching between development, staging, and production environments


B. It helps to debug the application
C. It improves code readability
D. It keeps configuration details in the codebase

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 86
How do WebSockets maintain an open connection?

A. By keeping an HTTP request open


B. By using long polling
C. By maintaining a persistent TCP connection
D. By creating a new connection for each message

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 87
Which of the following best describes WebSocket's advantages?

A. Full-duplex communication with low latency


B. Single-direction communication only
C. No support for large messages
D. Slower than HTTP

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 88
Which WebSocket event is fired when the connection is closed?

A. close
B. end
C. terminate
D. disconnect

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
QUESTION 89
What is the purpose of body parsers in Express.js middleware?

A. To parse incoming request bodies in various formats


B. To handle errors in the request body
C. To compress incoming requests
D. To convert request bodies to JSON

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 90
Which method in Express allows for chaining multiple middleware?

A. app.all()
B. app.use()
C. app.route()
D. app.middleware()

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 91
Which HTTP method is used to mount middleware that applies to a specific route?

A. app.use()
B. app.get()
C. app.post()
D. app.all()

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 92
What is the difference between a readable and a writable stream in Node.js?

A. Readable streams emit data that can be consumed, while writable streams accept data to write
B. Readable streams store data, while writable streams send data
C. Readable streams are for network operations, writable streams are for file I/O
D. Writable streams process data asynchronously, readable streams process it synchronously

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 93
Which stream method is used to pipe the output of one stream into another?

A. pipe()
B. link()
C. merge()
D. flow()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 94
Which method allows asynchronous reading of a file in Node.js?

A. fs.readFileSync()
B. fs.readFile()
C. fs.read()
D. fs.asyncRead()

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 95
Which of the following will create a new directory asynchronously?

A. fs.mkdirSync()
B. fs.createDirectory()
C. fs.mkdir()
D. fs.create()

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 96
Which of the following does the async keyword indicate in front of a function?

A. The function will return a Promise


B. The function executes synchronously
C. The function will handle asynchronous events
D. The function is error-prone

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 97
What does Promise.all() return when one of the promises fails?

A. Promise.reject()
B. Promise.all() ignores the failure
C. Promise.all() waits for all promises
D. Promise.all() rejects with the error of the first failed promise

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 98
At which phase does the Event Loop process I/O events?

A. Poll phase
B. Timer phase
C. Check phase
D. Immediate phase

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 99
What is the main role of the Event Loop in Node.js?

A. Handle HTTP requests


B. Manage event listeners and asynchronous operations
C. Execute synchronous code only
D. Process database queries

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
QUESTION 100
Which phase comes after the poll phase in the Node.js Event Loop?

A. Check phase
B. Immediate phase
C. Timer phase
D. Idle phase

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 101
Which of the following can be considered an advantage of using Node.js for server-side development?

A. High CPU usage


B. Non-blocking I/O model
C. Multi-threaded execution
D. Supports synchronous file I/O

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 102
What does the process.exit() method do in a Node.js application?

A. Exits the process without cleaning up resources


B. Stops the event loop and terminates the Node.js process
C. Exits the current function
D. Pauses the application execution

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 103
Which of the following is used to handle child processes in Node.js?

A. Os
B. http
C. child_process
D. fs

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 104
What does the module.exports object in Node.js do?

A. Exports data from one module to another


B. Sets the default global object
C. Imports data into the current module
D. Imports libraries from other modules

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 105
Which of the following is NOT a feature of Node.js modules?

A. Encapsulation of code
B. Code reusability
C. Blocking I/O
D. Support for synchronous code execution

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 106
Which of the following will import a file located in a different directory?

A. require('./myModule')
B. require('../myModule')
C. require('/myModule')
D. import myModule

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 107
Which command installs all dependencies listed in package.json?

A. npm install
B. npm update
C. npm upgrade
D. npm start

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 108
Which file is created when you initialize a Node.js project using npm init?

A. index.js
B. node_modules.json
C. package.json
D. dependencies.json

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 109
How can you uninstall a package without removing its dependencies?

A. npm remove --no-deps <package>


B. npm uninstall <package>
C. npm delete <package>
D. npm clear <package>

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 110
Which of the following is a correct way to use async/await in Node.js?

A. Using await inside non-async functions


B. Using async in place of promises
C. Wrapping the function call in a promise manually
D. Using await only with synchronous functions

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
QUESTION 111
How do you execute multiple promises in parallel using Promise.all()?

A. Promise.all([promise1, promise2])
B. Promise.all(promise1, promise2)
C. Promise.all(promise1 && promise2)
D. Promise.parallel([promise1, promise2])

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 112
Which is the best way to handle errors in async functions?

A. Using .catch() after calling the async function


B. Wrapping async calls inside try/catch blocks
C. Letting the function crash if an error occurs
D. Returning null or undefined for errors

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 113
In Node.js, what type of pattern is commonly used for managing events?

A. Publisher-Subscriber pattern
B. Observer pattern
C. Event Queue pattern
D. Request-Response pattern

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 114
What is emitted when an error occurs in Node.js Event Emitters?

A. error event
B. exception event
C. errorOccurred event
D. failure event

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 115
Which method allows you to remove all listeners for a specific event in Node.js?

A. emitter.removeAllListeners()
B. emitter.removeListeners()
C. emitter.clearListeners()
D. emitter.deleteListeners()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 116
What does app.listen() do in an Express.js application?

A. Starts a web server that listens for incoming HTTP requests


B. It listens for errors in the application
C. Starts a database connection
D. Mounts middleware on routes

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 117
How would you define a route for handling GET requests at the /home path in Express?

A. app.get('/home', function(req, res) {...})


B. app.route('/home').get(function(req, res) {...})
C. app.router('/home').get(function(req, res) {...})
D. app.router('/home').post(function(req, res) {...})

Correct Answer: AB
Section: (none)
Explanation

Explanation/Reference:

QUESTION 118
Which middleware is used to handle cookie parsing in Express?

A. cookie-parser
B. cookie-handler
C. cookie-manager
D. express-cookie

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 119
What is the purpose of using a .env file in Node.js projects?

A. To manage environment variables


B. To define constants
C. To store file paths
D. To store sensitive code

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 120
Which of the following is a best practice when dealing with untrusted data in Node.js applications?

A. Always sanitize input to prevent security vulnerabilities


B. Ignore potential security threats from untrusted data
C. Store sensitive data like passwords in plain text
D. Validate data only on the client side

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 121
Which logging library is often used in Node.js applications for structured logging?

A. Winston
B. log4js
C. morgan
D. All of the above

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:
QUESTION 122
Which event is triggered when a WebSocket connection is established?

A. Open
B. Connect
C. Start
D. Ready

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 123
How do you send data from a WebSocket server to the client?

A. ws.send(data)
B. ws.emit(data)
C. ws.push(data)
D. ws.broadcast(data)

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 124
What is the purpose of WebSocket's ping and pong messages?

A. To maintain the connection alive and measure latency


B. To send binary data
C. To exchange authentication tokens
D. To compress the message payload

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 125
What does the next() function do in middleware for handling requests in Express.js?

A. It proceeds to the next middleware or route handler


B. It closes the connection to the client
C. It terminates the request-response cycle
D. It suspends the request

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 126
Which type of middleware is executed before route handling middleware in Express?

A. Application-level middleware
B. Route-level middleware
C. Error-handling middleware
D. Built-in middleware

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 127
How can you limit the number of requests made by the client in a certain period?

A. By using rate-limiting middleware


B. By applying custom logic to each route
C. By using app.use() for validation
D. By setting cookies in the response

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 128
Which method is used to read data from a readable stream?

A. stream.read()
B. stream.pipe()
C. stream.output()
D. stream.get()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 129
What is the advantage of using streams over loading a file entirely into memory?

A. Streams allow reading and writing data as it is being processed, reducing memory usage
B. Streams store data in memory and thus are faster
C. Streams process files more slowly
D. Streams require less CPU usage

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 130
How can you pause a readable stream?

A. stream.pause()
B. stream.stop()
C. stream.close()
D. stream.suspend()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 131
Which of the following is the primary reason Node.js is preferred for I/O-heavy applications?

A. It uses a synchronous execution model


B. It uses non-blocking, event-driven architecture
C. It is easy to implement multi-threading
D. It runs on multiple processors concurrently

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 132
Which of the following is true about Node.js?

A. Node.js is used for frontend development only


B. Node.js is a multi-threaded framework
C. Node.js is a runtime environment that runs JavaScript code outside of the browser
D. Node.js is used only for building web pages

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:
QUESTION 133
Which built-in Node.js module helps you work with paths and file system operations?

A. http
B. path
C. events
D. fs

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 134
How would you require a JSON file in Node.js?

A. require('./data.json')
B. import('./data.json')
C. require('./data.json') (but only if it contains JavaScript code)
D. require('./data')

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 135
Which command can you use to create a custom module in Node.js?

A. node module.create
B. require('./myModule')
C. module.exports
D. Custom modules are not allowed in Node.js

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 136
What is the purpose of exports in Node.js?

A. It is used to define global variables


B. It is used to import external libraries
C. It is used to export functions or objects from a module
D. It initializes Node.js built-in modules

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 137
Which command installs a package globally?

A. npm install <package>


B. npm install <package> -g
C. npm add <package>
D. npm global-install <package>

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 138
How can you search for a package using NPM?

A. npm search <package>


B. npm find <package>
C. npm search --global <package>
D. npm query <package>

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 139
What is package-lock.json used for?

A. To lock the current version of Node.js


B. To lock the versions of dependencies for consistency
C. To specify the package manager version
D. To store the list of globally installed packages

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 140
What happens when you call an asynchronous function without a callback in Node.js?

A. The function execution is blocked until completion


B. An error is thrown
C. The callback is passed automatically
D. The function executes synchronously

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 141
What is the main difference between callbacks and promises in Node.js?

A. Promises are synchronous, while callbacks are asynchronous


B. Promises simplify chaining of asynchronous operations, while callbacks can lead to callback hell
C. Callbacks allow more fine-grained control over I/O operations
D. Promises are only useful for I/O operations, callbacks are for CPU-intensive tasks

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 142
Which of the following would you use to handle multiple asynchronous tasks and wait for them all to
complete?

A. Promise.any()
B. Promise.all()
C. async.parallel()
D. Promise.resolve()

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 143
What is the default maximum number of listeners for each event in Node.js's EventEmitter?

A. 10
B. 100
C. 50
D. 1

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
QUESTION 144
Which of the following is true about events in Node.js?

A. Events are used only for managing HTTP requests


B. Events provide an easy way to handle asynchronous operations without blocking
C. Node.js does not support event-driven programming
D. Events are only used for file system operations

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 145
How do you emit a custom event in Node.js?

A. emitter.emit('eventName')
B. emitter.raise('eventName')
C. emitter.dispatch('eventName')
D. emitter.trigger('eventName')

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 146
What does the express.Router() method do?

A. Creates a new middleware function


B. Creates a route handler for a specific path
C. Creates a new router object for routing HTTP requests
D. Sets a custom error handler

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 147
Which of the following is true about using middleware in Express.js?

A. Middleware runs before the route handler


B. Middleware runs after the route handler
C. Middleware can only handle POST requests
D. Middleware can only be used with static files
Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 148
Which HTTP method should you use to handle form submissions in Express?

A. app.get(
B. app.delete()
C. app.post()
D. app.head()

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 149
Which of the following should you consider when writing scalable applications in Node.js?

A. Using blocking I/O calls


B. Avoiding error handling
C. Leveraging asynchronous code
D. Writing all logic in a single function

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 150
Which of the following is a good practice when deploying a Node.js application in production?

A. Enabling full error logs in production


B. Running Node.js as a non-root user
C. Disabling clustering
D. Ignoring security updates

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 151
What is one of the most common ways to monitor a Node.js application in production?

A. Using console.log() for every request


B. Using application performance monitoring (APM) tools like New Relic or Datadog
C. Only running the application locally
D. Disabling error reporting in production

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 152
What type of protocol does WebSocket use for communication?

A. HTTP
B. HTTPS
C. TCP
D. UDP

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 153
What happens if you try to send a message over a closed WebSocket connection?

A. The message is queued


B. The message is lost
C. An error is thrown
D. The message is automatically retransmitted

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 154
Which of the following is a key feature of WebSocket?

A. One-way communication from client to server


B. Persistent, full-duplex communication between the client and server
C. Only supports binary data
D. Uses request-response model like HTTP

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
QUESTION 155
How can you create a custom error-handling middleware in Express.js?

A. By using app.use() with four arguments


B. By using app.error()
C. By using app.custom()
D. By defining an error event listener

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 156
Which middleware in Express helps in parsing incoming JSON data?

A. express.json()
B. express.bodyParser()
C. express.parseJSON()
D. express.body()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 157
How would you prevent a specific route in Express from being accessed by unauthorized users?

A. Using middleware for authentication and authorization checks


B. Redirecting users to the homepage
C. Disabling routing for that path
D. Allowing all routes to handle authentication

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 158
Which of the following methods can be used to pipe a readable stream to a writable stream?

A. stream.pipe(destination)
B. stream.writeTo(destination)
C. stream.transfer(destination)
D. stream.send(destination)

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 159
What type of stream is used for reading data from a file in Node.js?

A. Readable stream
B. Writable stream
C. Duplex stream
D. Transform stream

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 160
What method would you use to end a writable stream after writing data?

A. stream.close()
B. stream.end()
C. stream.stop()
D. stream.closeWrite()

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 161
Which Node.js function is used to get the current working directory?

A. process.cwd()
B. os.cwd()
C. path.cwd()
D. process.getcwd()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 162
What is the primary role of Node.js in the MEAN stack?

A. It provides the database interface


B. It is used for backend server-side logic
C. It is used for client-side rendering
D. It handles the routing of HTTP requests

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 163
Which of the following is NOT a common use case for Node.js?

A. Real-time web applications


B. APIs for single-page applications
C. Heavy computational tasks
D. Microservices

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 164
How would you load a local module in Node.js?

A. require('moduleName')
B. require('./moduleName')
C. import('./moduleName')
D. module.import('./moduleName')

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 165
Which of the following is the correct way to export a single function from a module in Node.js?

A. module.exports = function() { ... };


B. exports = function() { ... };
C. module.export = function() { ... };
D. export function() { ... };

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
QUESTION 166
Which Node.js module can be used to interact with the operating system and retrieve system
information?

A. Path
B. Os
C. http
D. fs

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 167
How would you view the details of a specific package installed via NPM?

A. npm show <package>


B. npm info <package>
C. npm details <package>
D. Both a and b

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 168
Which of the following NPM commands creates a package-lock.json file?

A. npm install
B. npm init
C. npm update
D. npm config set

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 169
What command is used to install a package as a development dependency in NPM?

A. npm install --dev <package>


B. npm install <package> --save-dev
C. npm dev-install <package>
D. npm install <package> -d
Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 170
Which function is used to handle the result of an asynchronous operation in a promise chain?

A. .catch()
B. .then()
C. .finally()
D. .complete()

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 171
What does the async keyword do in an asynchronous function?

A. It allows the function to be executed synchronously


B. It signals the function to return a promise
C. It automatically catches all errors in the function
D. It delays the execution of the function

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 172
What happens if you throw an error inside an async function?

A. It is caught automatically by the catch() method


B. It is thrown immediately
C. It creates a promise rejection
D. It logs the error to the console

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 173
Which of the following is true about event-driven architecture in Node.js?

A. It relies on synchronous execution of events


B. It uses callbacks and event emitters to handle multiple operations concurrently
C. It is used only for web servers
D. It does not support asynchronous programming

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 174
How can you modify the maximum number of listeners for an event in Node.js?

A. emitter.setMaxListeners(20)
B. emitter.maxListeners(20)
C. emitter.changeMaxListeners(20)
D. emitter.setListeners(20)

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 175
Which method would you use to listen for custom events in Node.js?

A. emitter.on('eventName', callback)
B. emitter.addListener('eventName', callback)
C. Both a and b
D. emitter.listen('eventName', callback)

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 176
Which middleware function is commonly used to log HTTP requests in Express.js?

A. Morgan
B. body-parser
C. cookie-parser
D. express-log

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
QUESTION 177
How would you add a route that listens for PUT requests at the /update path in Express?

A. app.put('/update', (req, res) => {...})


B. app.patch('/update', (req, res) => {...})
C. app.put('/update', (req) => {...})
D. app.post('/update', (req, res) => {...})

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 178
Which of the following is the correct way to handle static files in Express?

A. app.use(express.static('public'))
B. app.static('public')
C. app.useStatic('public')
D. app.staticFiles('public')

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 179
Which of the following is a best practice for handling errors in Node.js applications?

A. Throwing errors without logging them


B. Using try/catch for synchronous code and .catch() for promises
C. Letting errors propagate to the top level
D. Ignoring errors to prevent performance issues

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 180
Which of the following is the best approach for managing a large Node.js application?

A. Writing all the code in a single file


B. Using modules to break down the application into smaller components
C. Only using a single routing file for simplicity
D. Avoiding the use of external libraries

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 181
What should you do to handle uncaught exceptions in a Node.js application?

A. Let the process exit and restart it manually


B. Use process.on('uncaughtException', callback) to handle them
C. Ignore the error, Node.js will automatically handle it
D. Exit the process and do not restart it

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
WebSocket Communication (Extended)

QUESTION 182
Which WebSocket method would you use to send a message from the server to the client?

A. ws.send()
B. ws.emit()
C. ws.sendMessage()
D. ws.push(

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 183
Which of the following is the correct way to close a WebSocket connection from the server?

A. ws.close()
B. ws.disconnect()
C. ws.terminate()
D. ws.end()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 184
How do you handle WebSocket message events in the client?

A. socket.on('message', (data) => {...})


B. socket.receive('message', (data) => {...})
C. socket.message('message', (data) => {...})
D. socket.listen('message', (data) => {...})

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 185
How would you add a middleware that runs only for specific HTTP methods in Express?

A. app.use(method, middleware)
B. app.use('/path', method, middleware)
C. app[method]('/path', middleware)
D. app.method('/path', middleware)

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 186
Which of the following is used to serve static files in Express?

A. app.use(express.static(path))
B. app.serve(path)
C. app.staticFiles(path)
D. app.serveStatic(path)

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 187
How would you add a middleware for handling JSON payloads in Express.js?

A. app.use(express.json())
B. app.json(express())
C. app.bodyParser()
D. app.use(express.payload())

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
QUESTION 188
Which of the following streams can be used to transform data before passing it to the next stream?

A. Readable stream
B. Writable stream
C. Transform stream
D. Duplex stream

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 189
Which method is used to pause a writable stream?

A. stream.pause()
B. stream.stop()
C. stream.end()
D. stream.suspend()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 190
What is the purpose of the stream.finished() method in Node.js?

A. To check if the stream is currently active


B. To check if the stream has completed processing
C. To stop all ongoing operations
D. To close the stream immediately

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 191
What is the output of console.log(process.argv) in a Node.js program?

A. Array of command-line arguments passed to the program


B. Path of the current script
C. The Node.js version
D. List of dependencies in package.json

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 192
Which of the following would be the best way to ensure your Node.js application handles a large
number of concurrent users?

A. Use synchronous I/O operations


B. Use asynchronous I/O operations with callbacks or promises
C. Run Node.js in a single-threaded environment
D. Ignore error handling to improve performance

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 193
Which command would you use to check the version of Node.js installed on your system?

A. node –version
B. node –v
C. node version
D. Both a and b

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 194
What does require() do in Node.js?

A. Loads a file and evaluates it, returning the exported module


B. Loads a library into the global namespace
C. Executes the entire Node.js program
D. Imports a module from another server

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 195
How do you export an object from a Node.js module?

A. module.export = object
B. exports = object
C. module.exports = object
D. object.export()

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 196
Which of the following will correctly import the fs module in Node.js?

A. import fs from 'fs'


B. require('fs')
C. import * as fs from 'fs'
D. import module from 'fs'

Correct Answer: AB
Section: (none)
Explanation

Explanation/Reference:

QUESTION 197
What does the command npm uninstall <package> do?

A. Removes the package and its dependencies from the project


B. Removes the package from the global package registry
C. Removes the package only from the node_modules directory
D. Uninstalls the global NPM package

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 198
What does the npm outdated command do?

A. Lists all outdated packages that need updating


B. Displays the status of the current project
C. Lists all installed global packages
D. Updates packages to the latest version

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
QUESTION 199
What is the purpose of the npm update command?

A. It updates the project's dependencies to the latest versions specified in package.json


B. It updates Node.js itself
C. It upgrades NPM to the latest version
D. It only updates the dependencies in package-lock.json

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 200
Which of the following is a method used to handle multiple promises concurrently and return a single
promise?

A. Promise.all()
B. Promise.race()
C. Promise.finally()
D. Promise.any()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 201
What does await do in JavaScript?

A. It pauses the execution of the async function until the promise is resolved or rejected
B. It starts a promise-based function
C. It handles promise rejections
D. It waits for a setTimeout to finish

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 202
Which function is used to handle promise rejections in Node.js?

A. .catch()
B. .then()
C. .finally()
D. .reject()
Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 203
What is an event loop in Node.js?

A. A mechanism that schedules and processes events asynchronously in a non-blocking way


B. A loop that listens to events in real-time
C. A function that processes events sequentially
D. A framework for handling multiple clients

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 204
How can you remove all listeners for a specific event from an EventEmitter instance?

A. emitter.removeListener('eventName')
B. emitter.removeAllListeners('eventName')
C. emitter.off('eventName')
D. emitter.clearListeners('eventName')

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 205
What is the purpose of the once() method in Node.js EventEmitter?

A. To listen for events that should be triggered only once


B. To fire an event only once during program execution
C. To reset all events to be triggered once
D. To delay an event execution until a condition is met

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 206
Which method is used to send an HTTP response with a specific HTTP status code in Express?

A. res.statusCode(404)
B. res.sendStatus(404)
C. res.send(404)
D. res.status(404).send('Not Found')

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 207
Which of the following is used to parse incoming requests with JSON payloads in Express?

A. app.use(express.json())
B. app.use(bodyParser.json())
C. app.use(express.bodyParser())
D. app.bodyParser()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 208
How can you chain route handlers in Express.js?

A. Using app.route()
B. Using app.all()
C. Using app.handle()
D. Using app.middleware()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 209
Which of the following is a common practice for optimizing performance in Node.js?

A. Avoid using asynchronous code


B. Use global variables extensively to speed up access
C. Avoid using console.log() in production
D. Ignore error handling to avoid overhead

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:
QUESTION 210
When should you use environment variables in a Node.js application?

A. To store sensitive configuration data like API keys and database credentials
B. To store application logic
C. To store client-side data for use in templates
D. Only to store temporary data

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 211
What is the recommended way to handle long-running operations in a Node.js application?

A. Perform them synchronously to ensure they are completed before continuing


B. Use child processes or worker threads for CPU-intensive operations
C. Store them in the database and process them later
D. Always run them inside an event listener

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 212
Which event is triggered when the WebSocket connection is closed?

A. ws.disconnect
B. ws.close
C. ws.end
D. ws.onclose

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 213
How can you broadcast a message to all connected WebSocket clients from the server?

A. Send the message to each client individually using ws.send()


B. Use ws.broadcast()
C. Use ws.sendToAll()
D. Node.js does not support broadcasting natively

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 214
Which protocol is WebSocket built upon?

A. HTTP
B. HTTPS
C. TCP
D. UDP

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 215
Which of the following is the purpose of express.static() middleware?

A. To handle static file serving


B. To parse incoming JSON payloads
C. To manage authentication
D. To log HTTP requests

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 216
How would you use middleware to handle errors in Express.js?

A. app.use(errorHandler)
B. app.all('/error', errorHandler)
C. app.error(errorHandler)
D. app.use('/error', errorHandler)

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 217
What is the purpose of the next parameter in Express middleware?

A. It is used to pass control to the next middleware function in the stack


B. It is used to delay the execution of middleware
C. It stores a reference to the next middleware function
D. It signals the end of a middleware chain

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 218
Which of the following is used to run a Node.js application?

A. node <filename>
B. node run <filename>
C. node execute <filename>
D. node start <filename>

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 219
What is the default port number for a Node.js server?

A. 3000
B. 8080
C. 80
D. 5000

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 220
Which method is used to listen for incoming requests on a specific port in Node.js?

A. server.listen(port)
B. server.start(port)
C. server.open(port)
D. server.bind(port)

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
QUESTION 221
What happens if a module is required multiple times in Node.js?

A. It is loaded and executed again each time


B. It is cached after the first require and does not execute again
C. It throws an error
D. It is treated as a new module each time

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 222
Which of the following is true about CommonJS modules in Node.js?

A. They use the import statement for importing modules


B. They use require() for importing modules
C. They only support synchronous loading
D. They do not support module exports

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 223
How would you export multiple functions or variables from a Node.js module?

A. module.exports = [function1, function2]


B. module.exports = { function1, function2 }
C. exports = { function1, function2 }
D. module.exportMultiple = { function1, function2 }

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 224
How would you install a package globally using npm?

A. npm global install <package>


B. npm install --global <package>
C. npm add -g <package>
D. npm global <package>

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 225
What does the npm audit command do?

A. Scans your dependencies for security vulnerabilities


B. Displays the outdated packages in your project
C. Installs missing dependencies
D. Provides an overview of the project's structure

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 226
What command is used to create a package.json file for a Node.js project?

A. npm create
B. npm init
C. npm setup
D. npm package

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 227
Which of the following is true about setTimeout() in Node.js?

A. It immediately executes the function synchronously


B. It executes the function asynchronously after a specified delay
C. It executes the function only once per event loop
D. It blocks the event loop until the delay has passed

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 228
What does Promise.all() return when all promises are resolved successfully?

A. An array of the resolved values


B. A single resolved value
C. A resolved promise containing the first resolved value
D. A rejected promise

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 229
What does the finally() method do in a promise chain?

A. It catches any errors in the promise chain


B. It executes after the promise is settled (resolved or rejected)
C. It prevents further promise chaining
D. It cancels the promise execution

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 230
Which of the following is the best description of an event-driven architecture in Node.js?

A. A system where events (such as button clicks) trigger specific actions


B. A system where everything runs in a sequential, blocking order
C. A system where each action is triggered by time-based intervals
D. A system where events are polled in a loop for each iteration

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 231
How can you emit a custom event in Node.js using an EventEmitter?

A. emitter.emit('eventName', data)
B. emitter.trigger('eventName', data)
C. emitter.raise('eventName', data)
D. emitter.dispatch('eventName', data)

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
QUESTION 232
What is the purpose of the process.on('uncaughtException', callback) method?

A. It listens for and handles uncaught exceptions in the Node.js application


B. It processes all exceptions and prevents them from terminating the application
C. It generates uncaught exceptions deliberately for testing
D. It logs uncaught exceptions to the console

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 233
Which of the following is used to handle 404 errors in Express.js?

A. app.use((req, res, next) => { res.status(404).send('Not Found'); });


B. app.error(404, (req, res) => { ... });
C. app.useError(404, handler)
D. app.handle(404, (req, res) => { ... });

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 234
What is the purpose of the app.all() method in Express?

A. It is used to define a handler for all HTTP methods (GET, POST, etc.) for a given path
B. It is used to serve all types of files from a specific directory
C. It defines all routes globally for the app
D. It is used to listen for incoming requests on all ports

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 235
How would you use Express to parse a URL-encoded body (as submitted by a form)?

A. app.use(express.urlencoded({ extended: true }))


B. app.use(bodyParser.urlencoded({ extended: true }))
C. app.use(express.bodyParser({ extended: true }))
D. app.urlencoded()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 236
Which of the following best practices should be followed when deploying a Node.js application in
production?

A. Using synchronous file reads to improve performance


B. Enabling console.log() for debugging
C. Using environment variables to store sensitive information
D. Ignoring unhandled promise rejections

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 237
What is the recommended method for error handling in an asynchronous function in Node.js?

A. Ignoring the errors for better performance


B. Using a try/catch block inside an async function
C. Writing custom error handling functions for every operation
D. Using the error event in Node.js

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 238
What is the advantage of using worker threads in Node.js?

A. They allow for concurrent I/O operations in a single thread


B. They allow Node.js to execute CPU-intensive operations without blocking the event loop
C. They speed up event-driven asynchronous programming
D. They reduce memory usage by executing in the background

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 239
Which of the following would you use to send a message to all clients connected to the WebSocket
server?
A. ws.broadcast('message')
B. ws.sendToAll('message')
C. You would need to manually iterate over each connected WebSocket instance and send the
message
D. ws.emit('message')

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 240
Which event is fired when a message is received from the client in a WebSocket connection?

A. Message
B. Data
C. Receive
D. onmessage

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 241
How do you handle a WebSocket error in the client?

A. socket.on('error', callback)
B. socket.error(callback)
C. socket.onerror(callback)
D. socket.catch(callback)

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 242
Which of the following middleware functions is used to parse cookies in an Express.js app?

A. cookieParser()
B. express.cookie()
C. cookieParserMiddleware()
D. app.cookies()

Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:

QUESTION 243
What is the default status code returned by Express when no status code is specified?

A. 200 (OK)
B. 404 (Not Found)
C. 500 (Internal Server Error)
D. 301 (Moved Permanently)

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 244
Which of the following is used to prevent Cross-Origin Resource Sharing (CORS) issues in Express.js?

A. express-cors
B. cors middleware
C. app.enableCORS()
D. app.allowCrossOrigin()

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 245
Which of the following is a core module of Node.js?

A. Fs
B. Path
C. http
D. All of the above

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 246
Which command is used to run a Node.js file directly from the terminal?

A. node run <filename>


B. node start <filename>
C. node <filename>
D. node execute <filename>
Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 247
In Node.js, which method can you use to read a file asynchronously?

A. fs.readFileSync()
B. fs.readFile()
C. fs.read()
D. fs.loadFile()

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 248
How would you require a built-in Node.js module in your project?

A. import fs from 'fs'


B. require('fs')
C. import * as fs from 'fs'
D. load('fs')

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 249
Which method would you use to dynamically load a module in Node.js?

A. require()
B. import()
C. load()
D. module.import()

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 250
What does module.exports do in a Node.js module?
A. Exports the module’s public API
B. Import the module’s public API
C. Imports functions from other modules
D. Defines the entire module inside a file

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 251
What does the command npm run <script> do?

A. Executes a script defined in the package.json file


B. Installs a new package
C. Compiles JavaScript code
D. Runs the app in production mode

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 252
What does the npm install command do when run in an existing project?

A. Installs all dependencies listed in the package.json file


B. Updates the package.json file
C. Removes the node_modules directory
D. Installs a new dependency into the project

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 253
What is the purpose of the npm start command in a Node.js project?

A. It starts the server defined in the scripts section of package.json


B. It installs all project dependencies
C. It initializes a new Node.js application
D. It starts the app in debug mode

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
QUESTION 254
What does the setImmediate() function do in Node.js?

A. Executes a callback function after the current event loop completes


B. Executes a callback function after a specified delay
C. Executes a callback function asynchronously after a specified interval
D. Executes a callback function synchronously before the next event loop

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 255
What is the result of calling Promise.reject('error')?

A. It creates a resolved promise with the value 'error'


B. It immediately rejects the promise with the error message 'error'
C. It throws an error in the synchronous code
D. It creates a pending promise

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 256
What is a key difference between setTimeout() and setImmediate()?

A. setTimeout() executes a callback after the specified delay, while setImmediate() runs the callback
on the next iteration of the event loop
B. setTimeout() always runs synchronously, while setImmediate() is asynchronous
C. setTimeout() is used to handle errors, while setImmediate() handles regular tasks
D. setTimeout() executes in the next event loop, while setImmediate() waits until the script is finished

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 257
Which of the following is true about the EventEmitter class in Node.js?

A. It is used to handle HTTP requests in Node.js


B. It is used to manage file system operations
C. It allows an object to emit named events that listeners can respond to
D. It only supports one listener per event
Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 258
Which of the following is the correct syntax to add an event listener to an EventEmitter instance?

A. emitter.addListener('event', callback)
B. emitter.on('event', callback)
C. emitter.subscribe('event', callback)
D. emitter.event(callback)

Correct Answer: AB
Section: (none)
Explanation

Explanation/Reference:

QUESTION 259
What does the process.nextTick() function do in Node.js?

A. Executes a callback after the current operation completes, before the event loop continues
B. Executes a callback after the current event loop iteration
C. Schedules a task to be performed immediately
D. Immediately terminates the process and logs errors

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 260
Which of the following is the correct way to define a GET route in Express?

A. app.route('/path').get((req, res) => { ... })


B. app.get('/path', (req, res) => { ... })
C. app.define('/path').get((req, res) => { ... })
D. app.post('/path').get((req, res) => { ... })

Correct Answer: AB
Section: (none)
Explanation

Explanation/Reference:

QUESTION 261
Which middleware function would you use to parse incoming form data in Express?
A. express.bodyParser()
B. express.json()
C. express.urlencoded()
D. bodyParser()

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 262
What is the primary purpose of the next() function in Express middleware?

A. To terminate the request-response cycle


B. To send a response to the client
C. To pass control to the next middleware function
D. To execute the current middleware again

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 263
Which of the following is a best practice for handling errors in Node.js applications?

A. Always log errors to the console and allow the application to continue running
B. Return detailed error messages to the client to help debug
C. Use try/catch blocks and reject unhandled promise rejections
D. Let errors go unhandled to improve performance

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 264
What is the best way to scale a Node.js application?

A. Run the application on multiple threads in a single process


B. Use multiple instances of Node.js behind a load balancer
C. Use a single thread for handling multiple requests
D. Increase the number of synchronous I/O operations

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
QUESTION 265
What is the purpose of using dotenv in a Node.js application?

A. It helps to parse cookies from incoming HTTP requests


B. It allows you to manage environment variables easily in a .env file
C. It is used to run Node.js applications in production mode
D. It is a tool for managing API requests and responses

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 266
Which of the following is true about WebSocket communication in Node.js?

A. WebSockets require HTTP/2 for communication


B. WebSocket is a one-way communication protocol
C. WebSockets provide full-duplex communication between client and server
D. WebSockets can only be used with static websites

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 267
How would you close a WebSocket connection from the server side?

A. ws.close()
B. ws.disconnect()
C. ws.terminate()
D. ws.end()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 268
How can you handle errors when using WebSocket in a Node.js client?

A. socket.onerror = function(event) { ... }


B. socket.onError(function(event) { ... })
C. socket.catchError(function(event) { ... })
D. socket.handleError(function(event) { ... })
Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 269
Which of the following middleware functions would you use to serve static files in an Express.js
application?

A. app.static()
B. express.static()
C. app.serveStatic()
D. serve.static()

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 270
What is the primary function of middleware in an Express.js application?

A. To execute HTTP requests synchronously


B. To handle routing for each HTTP method
C. To process requests, modify responses, and pass control to the next middleware
D. To handle error handling and responses

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 271
Which middleware function is used to parse incoming JSON payloads in Express?

A. express.json()
B. express.bodyParser()
C. express.parseJson()
D. jsonParser()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 272
What does process.env in Node.js represent?
A. The current file directory
B. An object containing environment variables
C. The version of Node.js
D. A list of installed modules

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 273
How does Node.js handle multiple requests?

A. Using multithreading
B. Using a single-threaded, non-blocking I/O model
C. By creating multiple instances of the app
D. Using synchronous functions only

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 274
What is the purpose of exports in Node.js?

A. To import modules
B. To export objects and functions from a module
C. To read external files
D. To handle events

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 275
How do you make only specific functions or variables accessible from a Node.js module?

A. Use exports.specificFunction = function() { ... }


B. Use export default specificFunction
C. Use require.specificFunction
D. Place the function at the top of the file

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
QUESTION 276
Which of the following statements is false regarding module.exports and exports?

A. Both module.exports and exports are references to the same object initially
B. You can reassign exports directly to export an object
C. exports is a shorthand for module.exports
D. Using module.exports allows exporting a single function or object

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 277
What file is used by npm to determine the dependencies of a project?

A. package.json
B. npm-config.json
C. dependencies.json
D. module.json

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 278
What command updates all packages to their latest versions in an npm project?

A. npm update
B. npm upgrade
C. npm latest
D. npm all-update

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 279
What does the ^ symbol in package.json version numbers represent?

A. Updates to any version above the current


B. Updates to the latest major version
C. Updates to compatible minor versions
D. Updates to only the latest patch version
Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:
Asynchronous Programming (Extended)

QUESTION 280
Which of the following functions does not return a promise?

A. setTimeout()
B. fetch()
C. fs.promises.readFile()
D. Promise.resolve()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 281
How do you convert a callback-based function into a promise-based function in Node.js?

A. Using async/await
B. Using Promise.wrap()
C. Using Promise.promisify()
D. Using Promise.create()

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 282
What will Promise.race([p1, p2, p3]) return if p2 resolves first?

A. It returns the value from p2


B. It returns the values from all resolved promises
C. It waits for all promises to settle
D. It waits for the longest promise to resolve

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 283
Which method is used to remove a specific listener from an event in EventEmitter?

A. emitter.removeListener(event, listener)
B. emitter.off(event, listener)
C. emitter.removeEvent(event)
D. emitter(event, listener)

Correct Answer: AB
Section: (none)
Explanation

Explanation/Reference:

QUESTION 284
What event is emitted when an error occurs in Node.js?

A. Error
B. Exception
C. Crash
D. uncaughtException

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 285
How can you prevent an application from crashing when an unhandled error occurs in an
EventEmitter?

A. Listen to the error event on the emitter


B. Use try/catch in synchronous functions
C. Wrap the EventEmitter in a promise
D. Ignore all errors in the application

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
Express.js Framework (Extended)

QUESTION 286
How would you configure Express to serve static files from a directory?

A. app.use(express.static('public'))
B. app.static('public')
C. app.serve('public')
D. app.serveStatic('public')

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
QUESTION 287
What is the role of the app.listen() function in an Express application?

A. It defines the application’s routes


B. It binds the application to a network port for incoming connections
C. It starts the application in debug mode
D. It logs server requests

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 288
Which of the following methods defines middleware for handling JSON payloads in Express?

A. app.use(express.json())
B. app.use(express.bodyParser())
C. app.json()
D. app.bodyParser()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 289
What is the recommended way to secure environment variables in a Node.js project?

A. Storing them directly in the code


B. Using .env files and keeping them out of version control
C. Hard-coding them in package.json
D. Sharing them openly for all developers

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 290
What is a common way to improve application performance in Node.js?

A. Using synchronous file operations


B. Using asynchronous non-blocking methods
C. Blocking the event loop for heavy tasks
D. Using multiple single-threaded processes
Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 291
Which tool is commonly used for logging in production-grade Node.js applications?

A. console.log()
B. fs.appendFile()
C. Winston
D. logger.debug()

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 292
Which protocol upgrade does WebSocket use to establish a connection over HTTP?

A. HTTP/2
B. WebSocket handshake
C. TCP/IP upgrade
D. HTTP upgrade

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 293
Which event listener would you use to detect when a WebSocket connection is closed?

A. socket.on('disconnect')
B. socket.on('close')
C. socket.on('end')
D. socket.on('exit')

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 294
What is the purpose of ws.send() in a WebSocket server?

A. To send a message to a specific client


B. To send a message to all connected clients
C. To broadcast to all clients and servers
D. To close the connection

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 295
In Express, which method is typically used to handle errors across the application?

A. app.error()
B. app.use((err, req, res, next) => { ... })
C. app.catch((err) => { ... })
D. app.handleError((err) => { ... })

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 296
What is the order of middleware execution in Express.js?

A. Alphabetical order
B. In the order they are defined in the code
C. Based on middleware priority level
D. Random order

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 297
Which type of middleware can modify the request object in Express.js before it reaches the route
handler?

A. Error-handling middleware
B. Application-level middleware
C. Request-modifying middleware
D. Route handler middleware

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
QUESTION 298
Which of the following is an example of a readable stream in Node.js?

A. fs.createReadStream()
B. fs.writeFile()
C. fs.appendFile()
D. http.get()

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 299
Which event is emitted by writable streams when they are ready to accept more data?

A. Data
B. Drain
C. Ready
D. open

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 300
What is the purpose of a for...of loop in JavaScript?

A. Iterates over each property of an object


B. Iterates over each character in a string
C. Iterates over iterable objects like arrays, strings, and sets
D. Iterates in reverse order

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 301
What is the output of the following code? javascript const arr = [1, 2, 3]; for (let i = 0; i < arr.length; i++)
{ if (i === 1) break; console.log(arr[i]); }

A. 1, 2, 3
B. 2
C. 1
D. 1, 2
Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 302
Which loop would you use when the number of iterations is unknown but depends on a condition?

A. for loop
B. while loop
C. do...while loop
D. none of the above

Correct Answer: AB
Section: (none)
Explanation

Explanation/Reference:

QUESTION 303
What is the main difference between for...in and for...of loops?

A. for...in loops through array elements, and for...of loops through object properties
B. for...in loops through object properties, and for...of loops through iterable elements
C. Both loops function identically
D. for...in is used only for arrays

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 304
How many times will the following loop execute? javascript let count = 0; while (count < 5) { count++; }

A. 0
B. 4
C. 5
D. Infinite

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 305
Which of the following is an ordered, indexed data structure in JavaScript?
A. Object
B. Array
C. Set
D. Map

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 306
Which of these statements about Set in JavaScript is true?

A. Set only stores unique values


B. Set stores key-value pairs
C. Set maintains insertion order of items
D. Both a and c

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 307
How can you access the value for a specific key in a Map?

A. map[key]
B. map.get(key)
C. map[key].value
D. map.getValue(key)

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 308
What is the result of Array.from(new Set([1, 2, 2, 3, 4]))?

A. [1, 2, 2, 3, 4]
B. [1, 2, 3, 4]
C. [2, 3, 4]
D. [1, 3, 4]

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
QUESTION 309
Which of these data structures does not allow duplicate values by default?

A. Array
B. Object
C. Set
D. Map

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 310
What is a callback function in JavaScript?

A. A function that is called automatically at the end of every function


B. A function passed as an argument to another function and executed later
C. A function that executes immediately upon definition
D. A synchronous function that runs after another function completes

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 311
Which of the following correctly demonstrates a callback function? javascript function greet(name,
callback) { console.log('Hello ' + name); callback(); } greet('Alice', function() { console.log('Callback
executed'); });

A. Only logs "Hello Alice"


B. Only logs "Callback executed"
C. Logs "Hello Alice" and then "Callback executed"
D. Throws an error

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 312
What is the main advantage of using callbacks in JavaScript?

A. They allow synchronous code to execute faster


B. They allow for more readable code
C. They enable asynchronous execution, allowing code to continue running while waiting for another
process to complete
D. They prevent errors from occurring in code

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 313
What is an example of a built-in JavaScript method that uses a callback function?

A. forEach()
B. map()
C. setTimeout()
D. All of the above

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 314
What is a common issue when using callbacks in JavaScript, especially when nesting multiple
callbacks?

A. Callback rejection
B. Callback rejection
C. Callback hell
D. Callback cycle

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 315
Which of the following is a correct syntax for defining a function in JavaScript?

A. function myFunc { ... }


B. let myFunc() = { ... }
C. function myFunc() { ... }
D. let myFunc[] = { ... }

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:
QUESTION 316
What is the output of the following code? javascript function add(a, b) { return a + b; } console.log(add
(2, 3));

A. Undefined
B. 23
C. 5
D. NaN

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 317
What keyword is used to define an arrow function in JavaScript?

A. =>
B. ->
C. :
D. None of the above

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 318
Which of these functions immediately invokes itself upon definition?

A. Anonymous function
B. Named function
C. IIFE (Immediately Invoked Function Expression)
D. Callback function

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 319
What is the default return value of a function in JavaScript if no return statement is specified?

A. Null
B. Undefined
C. NaN
D. false
Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
Objects

QUESTION 320
Which of the following is a valid way to create an object in JavaScript?

A. let obj = { }
B. let obj = Object.create()
C. let obj = new Object({ })

Correct Answer: AC
Section: (none)
Explanation

Explanation/Reference:

QUESTION 321
What is the result of the following code? javascript const person = { name: 'Alice', greet: function()
{ return 'Hello ' + this.name; } }; console.log(person.greet());

A. Hello Alice
B. Hello undefined
C. Undefined
D. Throws an error

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 322
Which method is used to get an array of keys in an object?

A. Object.values()
B. Object.keys()
C. Object.entries()
D. Object.list()

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 323
How can you prevent modifications to an object in JavaScript?

A. Object.lock()
B. Object.preventExtensions()
C. Object.seal()
D. Object.freeze()

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 324
What will Object.assign() do when used on an object?

A. It merges properties from one or more source objects into a target object
B. It prevents extensions on the object
C. It deep clones the object
D. It deletes all properties in the object

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 325
What is the purpose of semicolons in JavaScript?

A. To separate HTML from JavaScript


B. To end statements (optional in most cases)
C. To enclose a function
D. To indicate variable declarations

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 326
What are reserved keywords in JavaScript?

A. Words that can be used as variables


B. Words that have a predefined meaning and cannot be used as identifiers
C. Words only used in comments
D. Any English word

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
QUESTION 327
Which of the following is a correct variable name in JavaScript?

A. var 1name
B. var name@
C. var $name
D. var name%

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 328
What is an expression in JavaScript?

A. value-producing piece of code


B. Only a variable declaration
C. Only a function call
D. A line of code that does not produce a value

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 329
What is the output of console.log(2 + '3');?

A. 5
B. 23
C. NaN
D. undefined

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 330
What does the expression 5 == '5' return in JavaScript?

A. true
B. false
C. undefined
D. Throws an error

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 331
Which of the following is not a primitive data type in JavaScript?

A. String
B. Boolean
C. Object
D. Undefined

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 332
What will typeof NaN return in JavaScript?

A. 'undefined'
B. 'number'
C. 'NaN'
D. 'null'

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 333
What does null represent in JavaScript?

A. The absence of any value or object


B. A number
C. A data type
D. Undefined

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 334
Which keyword is used to define a class in JavaScript?

A. define
B. class
C. constructor
D. object

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 335
What is a constructor in a JavaScript class?

A. A method for initializing class properties


B. A method for deleting properties
C. A method only used to define functions
D. A variable inside a class

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 336
How would you create an instance of a class Person in JavaScript?

A. Person.create()
B. let p = new Person()
C. let p = Person()
D. let p = Person.new()

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 337
Which keyword declares a block-scoped variable in JavaScript?

A. var
B. let
C. const
D. Both b and c

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:
QUESTION 338
What will happen if you try to reassign a const variable?

A. It will change the value


B. It will throw an error
C. It will create a new variable
D. t will be ignored

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 339
Which of the following is the correct way to define a global variable?

A. Using const within a function


B. Using let within a function
C. Using var outside of any function or block
D. Using const outside of any function or block

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 340
What is the default return value of a function that does not explicitly return a value?

A. undefined
B. null
C. 0
D. false

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 341
How do you define a function expression in JavaScript?

A. function add() { ... }


B. let add = function() { ... }
C. function = add() { ... }
D. let add() { ... }

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 342
Which is an example of a higher-order function?

A. function myFunction() { ... }


B. setTimeout(() => { ... }, 1000)
C. function(a, b) { return a + b; }
D. const add = 5 + 3;

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 343
In JavaScript, what does the this keyword refer to in a global context?

A. window object in the browser


B. document object in the browser
C. Current function
D. Undefined

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 344
What does this refer to in a regular function?

A. The global object


B. The function itself
C. The caller of the function
D. The last object created

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 345
Which of the following is a correct arrow function syntax?

A. (a, b) => { return a + b; }


B. function => (a, b) { return a + b; }
C. (a, b) => return a + b;
D. let add = a, b => { return a + b; }

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 346
How does this behave differently in arrow functions compared to regular functions?

A. this refers to the global object in arrow functions


B. this is lexically bound, meaning it uses this from the enclosing context
C. this always refers to the function itself in arrow functions
D. this does not exist in arrow functions

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 347
Which of the following statements about arrow functions is true?

A. Arrow functions cannot be used as methods in an object


B. Arrow functions automatically bind this to the global scope
C. Arrow functions can be used with arguments object
D. Arrow functions are syntactically similar to const functions

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 348
What is block scope in JavaScript?

A. Scope of variables defined within a single line


B. Scope of variables defined within a block { }
C. Scope of variables defined globally
D. Scope of variables within functions only

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
QUESTION 349
Which variables are accessible within a function’s scope?

A. Only the variables declared within the function


B. Only global variables
C. Variables defined in the function and any parent scopes
D. None of the above

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 350
What will array.push(4) do if array = [1, 2, 3]?

A. Returns [1, 2, 3]
B. Adds 4 to the beginning
C. Adds 4 to the end of the array
D. Throws an error

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 351
How do you create a copy of an array in JavaScript?

A. let newArray = array.copy()


B. let newArray = array.map()
C. let newArray = [...array]
D. let newArray = array.slice(1)

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 352
What is the syntax for using template literals in JavaScript?

A. "string ${variable}"
B. 'string ${variable}'
C. `string ${variable}`
D. None of the above

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 353
Which of the following correctly uses a template literal to embed a variable name?

A. console.log('Hello ' + name);


B. console.log(Hello ${name});
C. console.log("Hello ${name}");
D. console.log('Hello name');

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 354
How do you enable strict mode in JavaScript?

A. use strict;
B. 'strict mode';
C. import 'strict mode';
D. "use strict";

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 355
What is one primary benefit of strict mode in JavaScript?

A. It speeds up code execution


B. It allows the use of undeclared variables
C. It prevents the use of certain error-prone practices
D. It removes all warnings

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 356
What will happen if JavaScript encounters an undeclared variable in strict mode?

A. It will silently ignore it


B. It will treat it as a global variable
C. It will throw a reference error
D. It will treat it as undefined

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 357
Which characters are allowed in JavaScript variable names?

A. Letters, digits, underscores, and dollar signs


B. Letters only
C. Letters and symbols
D. Only letters and underscores

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 358
What does the typeof operator return for an array in JavaScript?

A. 'object'
B. 'array'
C. 'object[]'
D. 'undefined'

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 359
What will be the output of console.log(5 + 2 * 3);?

A. 21
B. 11
C. 15
D. 17

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
QUESTION 360
Which operator checks for both value and type equality in JavaScript?

A. ==
B. =
C. ===
D. !==

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 361
What does typeof null return in JavaScript?

A. 'null'
B. 'object'
C. 'undefined'
D. 'NaN'

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 362
Which of the following values is falsy in JavaScript?

A. 0
B. ""
C. null
D. All of the above

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 363
How do you check if a variable x is a number?

A. x.isNumber()
B. typeof x === 'number'
C. isNaN(x)
D. typeof x == number

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
Classes

QUESTION 364
How do you define a method inside a JavaScript class?

A. method() { ... } inside class body


B. method: function() { ... } inside class body
C. class.method() { ... }
D. method = function() { ... }

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 365
What is inheritance in JavaScript classes?

A. Copying properties from one class to another


B. Allowing a class to extend another class, inheriting its methods and properties
C. A mechanism to make a property private
D. Adding methods to classes dynamically

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 366
Which keyword is used to extend a class from another class in JavaScript?

A. inherit
B. extends
C. implement
D. include

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 367
Which keyword should you use to prevent reassignment of a variable?

A. let
B. const
C. var
D. static

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 368
What will console.log(x); output if x is declared with let but not initialized?

A. undefined
B. Throws a reference error
C. null
D. 0

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 369
Which statement correctly declares a constant array?

A. const arr = [];


B. let const arr = [];
C. arr const = [];
D. arr = const [];

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 370
How do you call a function myFunction with arguments 5 and 10?

A. myFunction{5, 10}
B. myFunction[5, 10]
C. myFunction(5, 10)
D. myFunction: 5, 10

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:
QUESTION 371
Which function does not return a value?

A. console.log()
B. Math.max()
C. parseInt()
D. alert()

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 372
What does this refer to in a method of an object?

A. Global object
B. The object itself
C. Window object
D. Undefined

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 373
What does this refer to in a function defined in strict mode?

A. null
B. Global object
C. undefined
D. Window object

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 374
Why can't arrow functions be used as constructors in JavaScript?

A. They don't support this


B. They are not functions
C. They throw errors when used with new
D. They are always anonymous

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 375
Which of the following is true about arrow functions?

A. They inherit this from their enclosing context


B. They bind this dynamically
C. They redefine this
D. They cannot take parameters

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 376
What will for(let i = 0; i < 3; i++) { console.log(i); } output?

A. 0123
B. 012
C. 123
D. Nothing

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 377
Which statement immediately stops a loop?

A. break
B. continue
C. return
D. stop

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
Scopes

QUESTION 378
What is the primary difference between let and var?

A. let has function scope, and var has block scope


B. let has block scope, and var has function scope
C. Both are identical
D. let can be redeclared

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 379
Which keyword will give a variable a block scope?

A. var
B. global
C. let
D. static

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:
Arrays

QUESTION 380
What does Array.isArray([1, 2, 3]) return?

A. false
B. true
C. undefined
D. null

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 381
How do you find the length of an array in JavaScript?

A. array.size
B. array.length
C. array.length()
D. array.getSize()

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
QUESTION 382
How do you insert a variable name into a template literal?

A. Hello + name +
B. 'Hello + ${name}'
C. `Hello ${name}`
D. Hello (name)

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 383
What is the main advantage of template literals over regular strings?

A. They are always shorter


B. They support multi-line strings and embedded expressions
C. They run faster
D. They enforce strict mode

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 384
What happens if you assign a value to an undeclared variable in strict mode?

A. The variable is automatically declared


B. It throws a reference error
C. It creates a new global variable
D. It assigns undefined

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 385
In which way can strict mode be applied to JavaScript code?

A. Adding "use strict"; at the beginning of a script or function


B. Declaring a const variable
C. Using an arrow function
D. Adding strict = true;

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 386
What will console.log(x) output if x is not declared in the script but in strict mode?

A. undefined
B. Throws a reference error
C. null
D. It will create the variable automatically

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 387
Which keyword is used to define private properties in a JavaScript class (as of ES2022)?

A. private
B. const
C. # before the property name
D. __ before the property name

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 388
What will typeof function(){} === 'function' return?

A. false
B. true
C. Throws an error
D. undefined

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 389
What is a closure in JavaScript?

A. A nested function with access to the outer function’s scope


B. A way to initialize classes
C. A way to end loops early
D. A reserved keyword in strict mode

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

You might also like