Q1: What is Node.js primarily used for?
Options: A) Frontend development, B) Database management, C) Server-side JavaScript runtime, D)
Styling web pages
Answer: C) Server-side JavaScript runtime
Explanation: Node.js enables developers to run JavaScript on the server side, making it ideal for building
scalable network applications.
Q2: Which model is Node.js built upon to handle operations?
Options: A) Multi-threaded blocking I/O, B) Event-driven non-blocking I/O, C) Synchronous I/O, D) Batch
processing
Answer: B) Event-driven non-blocking I/O
Explanation: Node.js uses an event-driven non-blocking I/O model that efficiently manages
asynchronous operations.
Q3: What is one key advantage of using Node.js?
Options: A) Inflexible scalability, B) High memory consumption, C) Real-time application support, D)
Limited performance
Answer: C) Real-time application support
Explanation: Node.js is well-suited for real-time applications due to its asynchronous and non-blocking
architecture.
Q4: Who originally created Node.js?
Options: A) Brendan Eich, B) Ryan Dahl, C) Guido van Rossum, D) James Gosling
Answer: B) Ryan Dahl
Explanation: Ryan Dahl is the creator of Node.js, introduced in 2009 to help build scalable network
applications.
Q5: How does Node.js differ from traditional backend frameworks like PHP?
Options: A) It uses synchronous processing exclusively, B) It supports multi-threaded execution by
default, C) It operates on a non-blocking, event-driven model, D) It does not support server-side
operations
Answer: C) It operates on a non-blocking, event-driven model
Explanation: Unlike many traditional frameworks, Node.js uses a non-blocking, event-driven model,
which makes it highly efficient for I/O-intensive operations.
Q6: In Node.js architecture, what is the role of the event loop?
Options: A) To manage file system access, B) To handle asynchronous callbacks, C) To compile code, D)
To schedule CPU-intensive tasks
Answer: B) To handle asynchronous callbacks
Explanation: The event loop is central to Node.js, managing asynchronous callbacks and enabling non-
blocking I/O.
Q7: What is a primary characteristic of Node.js’s single-threaded model?
Options: A) It can handle multiple threads simultaneously, B) It uses a thread pool for I/O operations, C)
It relies solely on parallel processes, D) It blocks on every I/O call
,Answer: B) It uses a thread pool for I/O operations
Explanation: Although Node.js runs on a single thread, it leverages a thread pool for certain I/O
operations to maintain non-blocking behavior.
Q8: What are worker threads in Node.js used for?
Options: A) Handling synchronous I/O, B) Offloading CPU-intensive tasks, C) Managing database
connections, D) Rendering UI components
Answer: B) Offloading CPU-intensive tasks
Explanation: Worker threads allow Node.js to handle CPU-bound tasks by offloading them from the
main event loop.
Q9: What is the purpose of buffers in Node.js?
Options: A) To store database records, B) To handle streams of binary data, C) To compile JavaScript
code, D) To schedule events
Answer: B) To handle streams of binary data
Explanation: Buffers in Node.js are used to efficiently manage binary data, especially when working with
streams.
Q10: Which module in Node.js is used for working with the file system?
Options: A) http, B) url, C) fs, D) os
Answer: C) fs
Explanation: The fs module provides an API for interacting with the file system, such as reading and
writing files.
Q11: What does the require() function do in Node.js?
Options: A) Starts the server, B) Imports modules, C) Compiles code, D) Manages databases
Answer: B) Imports modules
Explanation: The require() function is used to load and cache JavaScript modules in Node.js.
Q12: How can you create a custom module in Node.js?
Options: A) Use the module.create() method, B) Write code in a separate file and export functions using
module.exports, C) Insert code directly into package.json, D) Use the built-in customModule function
Answer: B) Write code in a separate file and export functions using module.exports
Explanation: Custom modules are created by writing code in separate files and exporting the
functionality with module.exports.
Q13: Which command is used to initialize a new Node.js project with npm?
Options: A) npm start, B) npm init, C) npm create, D) npm install
Answer: B) npm init
Explanation: The npm init command creates a new package.json file to initialize a Node.js project.
Q14: What file contains metadata and dependency information in a Node.js project?
Options: A) node.config, B) package.json, C) module.js, D) npmfile
Answer: B) package.json
Explanation: package.json holds metadata, dependencies, and scripts for a Node.js project.
Q15: What is the benefit of using semantic versioning in npm packages?
Options: A) It makes packages run faster, B) It provides a clear versioning system for dependency
,management, C) It increases package size, D) It disables updates
Answer: B) It provides a clear versioning system for dependency management
Explanation: Semantic versioning (semver) helps manage package versions by indicating compatibility
and changes between releases.
Q16: Which of the following is a correct way to handle asynchronous operations in Node.js?
Options: A) Using synchronous loops, B) Using callbacks, C) Blocking the event loop, D) Using global
variables
Answer: B) Using callbacks
Explanation: Callbacks are a fundamental method in Node.js for handling asynchronous operations.
Q17: How do Promises improve asynchronous code handling in Node.js?
Options: A) They eliminate asynchronous code entirely, B) They allow chaining and handling of
asynchronous operations, C) They force code to run synchronously, D) They replace functions
completely
Answer: B) They allow chaining and handling of asynchronous operations
Explanation: Promises provide a cleaner way to manage asynchronous code by supporting chaining and
improved error handling.
Q18: What does the async keyword indicate in a JavaScript function?
Options: A) That the function is synchronous, B) That the function returns a promise, C) That the
function uses callbacks only, D) That the function is deprecated
Answer: B) That the function returns a promise
Explanation: The async keyword marks a function as asynchronous, automatically wrapping its return
value in a Promise.
Q19: Which syntax is used to wait for a promise to resolve in asynchronous code?
Options: A) await, B) pause, C) waitFor, D) sleep
Answer: A) await
Explanation: The await keyword pauses the execution of an async function until the promise resolves.
Q20: How does the EventEmitter class contribute to Node.js programming?
Options: A) It manages database connections, B) It handles event-driven programming, C) It creates
HTTP servers, D) It compiles JavaScript code
Answer: B) It handles event-driven programming
Explanation: The EventEmitter class allows objects to emit events and register listeners, forming the
basis for event-driven programming in Node.js.
Q21: Which statement is true regarding error handling in synchronous Node.js code?
Options: A) Errors must always be ignored, B) Errors are handled using try/catch blocks, C) Errors are
automatically corrected, D) Synchronous code never produces errors
Answer: B) Errors are handled using try/catch blocks
Explanation: In synchronous code, try/catch blocks are used to capture and handle errors effectively.
Q22: What is a common pattern for handling errors in asynchronous code?
Options: A) Using error-first callbacks, B) Using try/catch exclusively, C) Ignoring errors, D) Restarting the
event loop
, Answer: A) Using error-first callbacks
Explanation: The error-first callback pattern passes an error as the first argument to callbacks, allowing
for standardized error handling.
Q23: Which tool can be used to debug Node.js applications?
Options: A) Node Inspector, B) Chrome DevTools, C) Firebug, D) Visual Studio Code only
Answer: B) Chrome DevTools
Explanation: Chrome DevTools, among others, can be used with Node.js to inspect and debug code
through the built-in debugger.
Q24: What does the node --inspect command do?
Options: A) Starts a new server, B) Launches the Node.js debugger, C) Compiles the code, D) Installs
modules automatically
Answer: B) Launches the Node.js debugger
Explanation: The node --inspect command starts Node.js with debugging enabled, allowing remote
debugging through tools like Chrome DevTools.
Q25: How can logging be beneficial in Node.js applications?
Options: A) It slows down the application, B) It helps in debugging and monitoring application
performance, C) It increases file sizes, D) It prevents asynchronous operations
Answer: B) It helps in debugging and monitoring application performance
Explanation: Logging provides insights into application behavior, which aids in debugging and
performance monitoring.
Q26: What module is used to create HTTP servers in Node.js?
Options: A) fs, B) http, C) url, D) net
Answer: B) http
Explanation: The http module is designed to create and manage HTTP servers in Node.js.
Q27: How do you define routes in a basic Node.js HTTP server?
Options: A) By using the express framework exclusively, B) By manually checking the request URL, C) By
using database queries, D) By modifying package.json
Answer: B) By manually checking the request URL
Explanation: In a basic HTTP server, developers inspect the request URL to determine the route and
handle it accordingly.
Q28: What is a RESTful API?
Options: A) An API that only supports XML, B) An API that uses REST architecture principles, C) An API
without any endpoints, D) An API that works offline
Answer: B) An API that uses REST architecture principles
Explanation: RESTful APIs adhere to REST principles, providing scalable and stateless communication
between client and server.
Q29: What protocol is used by WebSockets for real-time communication?
Options: A) HTTP, B) FTP, C) WS/WSS, D) SMTP
Answer: C) WS/WSS