Node.js is built on Chrome's V8 JavaScript engine, which compiles JavaScript directly to native machine code.
Incorrect! Try again.
2Which of the following best describes the nature of Node.js?
A.Single-threaded and blocking
B.Multi-threaded and non-blocking
C.Single-threaded and non-blocking
D.Multi-threaded and blocking
Correct Answer: Single-threaded and non-blocking
Explanation:
Node.js uses a single-threaded event loop architecture but handles I/O operations asynchronously (non-blocking).
Incorrect! Try again.
3Who created Node.js?
A.Tim Berners-Lee
B.Brendan Eich
C.Jordan Walke
D.Ryan Dahl
Correct Answer: Ryan Dahl
Explanation:
Ryan Dahl created Node.js in 2009.
Incorrect! Try again.
4What does REPL stand for in the context of Node.js?
A.Read Evaluate Process Loop
B.Run Execute Print Loop
C.Read Execute Process List
D.Read Eval Print Loop
Correct Answer: Read Eval Print Loop
Explanation:
REPL stands for Read Eval Print Loop, an interactive shell that processes Node.js expressions.
Incorrect! Try again.
5Which command allows you to enter the Node.js REPL environment in a terminal?
A.node
B.npm start
C.repl
D.js
Correct Answer: node
Explanation:
Typing 'node' in the command prompt without arguments starts the REPL session.
Incorrect! Try again.
6In the Node.js REPL, what does the underscore variable (_) represent?
A.The last evaluated result
B.An undefined variable
C.The current directory
D.The global scope
Correct Answer: The last evaluated result
Explanation:
The underscore (_) serves as a special variable that stores the result of the previously executed expression.
Incorrect! Try again.
7Which command is used to initialize a new Node.js project and create a package.json file?
A.npm install
B.npm init
C.npm start
D.npm new
Correct Answer: npm init
Explanation:
The 'npm init' command guides you through creating a package.json file for your project.
Incorrect! Try again.
8Which flag can be used with 'npm init' to skip the questionnaire and use default values?
A.--default
B.-y
C.-f
D.--skip
Correct Answer: -y
Explanation:
The '-y' (or --yes) flag skips the interactive questions and creates a package.json with default settings.
Incorrect! Try again.
9Where does npm install the dependencies for a local project by default?
A./usr/local/lib
B.node_modules
C.global_modules
D.npm_packages
Correct Answer: node_modules
Explanation:
npm installs local dependencies in a folder named 'node_modules' within the project root.
Incorrect! Try again.
10Which file stores the metadata and dependency list for a Node.js project?
A.node_modules
B.config.xml
C.index.js
D.package.json
Correct Answer: package.json
Explanation:
The package.json file holds metadata relevant to the project, including dependencies, scripts, and version info.
Incorrect! Try again.
11Which function is used to include modules in Node.js?
A.require()
B.fetch()
C.include()
D.import()
Correct Answer: require()
Explanation:
In CommonJS (default Node.js module system), 'require()' is used to load modules.
Incorrect! Try again.
12Which of the following is a Core Module in Node.js?
A.express
B.lodash
C.fs
D.mongoose
Correct Answer: fs
Explanation:
'fs' (File System) is a built-in core module in Node.js. The others are third-party modules.
Incorrect! Try again.
13How do you export a function or object from a module in Node.js using CommonJS?
A.return module
B.module.exports
C.export default
D.exports.module
Correct Answer: module.exports
Explanation:
The 'module.exports' object is used to define what a module exposes to other files using 'require'.
Incorrect! Try again.
14Which syntax is correct to import a local module located in the same directory?
A.import moduleName
B.require('/moduleName')
C.require('moduleName')
D.require('./moduleName')
Correct Answer: require('./moduleName')
Explanation:
Local modules must be prefixed with './' (or '../' for parent directories) to distinguish them from core or node_modules.
Incorrect! Try again.
15What is the purpose of the 'events' module in Node.js?
A.To handle and trigger events
B.To handle HTTP requests
C.To handle file operations
D.To stream data
Correct Answer: To handle and trigger events
Explanation:
The 'events' module allows objects (EventEmitters) to emit named events that cause Function objects (listeners) to be called.
Incorrect! Try again.
16Which class is the primary component of the 'events' module?
A.EventListener
B.EventHandler
C.EventDispatcher
D.EventEmitter
Correct Answer: EventEmitter
Explanation:
The EventEmitter class is the core of the events module.
Incorrect! Try again.
17Which method of EventEmitter is used to register a listener for an event?
A.listen()
B.emit()
C.trigger()
D.on()
Correct Answer: on()
Explanation:
The 'on()' method is used to register a callback function (listener) that executes when a specific event is emitted.
Incorrect! Try again.
18Which method of EventEmitter causes an event to occur?
A.dispatch()
B.fire()
C.call()
D.emit()
Correct Answer: emit()
Explanation:
The 'emit()' method triggers the event, causing all registered listeners to execute.
Incorrect! Try again.
19What is a 'callback' in Node.js?
A.A blocking function
B.A function passed as an argument to be executed later
C.A global variable
D.A recursive loop
Correct Answer: A function passed as an argument to be executed later
Explanation:
A callback is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.
Incorrect! Try again.
20What is the convention for the first argument of a Node.js callback function?
A.The result data
B.The configuration object
C.The error object (or null)
D.The callback function itself
Correct Answer: The error object (or null)
Explanation:
Node.js follows the 'error-first callback' convention, where the first argument is reserved for an error object (if any), and subsequent arguments are for success data.
Incorrect! Try again.
21What is 'Callback Hell'?
A.Deeply nested callbacks making code hard to read
B.When a callback never executes
C.A security vulnerability
D.A syntax error in callbacks
Correct Answer: Deeply nested callbacks making code hard to read
Explanation:
Callback Hell (or Pyramid of Doom) refers to heavily nested callback functions that make code difficult to maintain and debug.
Incorrect! Try again.
22Which method is used to read a file asynchronously in Node.js?
A.fs.open()
B.fs.read()
C.fs.readFile()
D.fs.readFileSync()
Correct Answer: fs.readFile()
Explanation:
fs.readFile() reads the entire contents of a file asynchronously.
Incorrect! Try again.
23What happens if you use 'fs.writeFile()' on an existing file?
A.It creates a backup copy
B.It replaces the file content
C.It appends data to the end
D.It throws an error
Correct Answer: It replaces the file content
Explanation:
fs.writeFile() overwrites the file if it already exists.
Incorrect! Try again.
24Which 'fs' method is used to add data to a file without overwriting it?
A.fs.insert()
B.fs.addFile()
C.fs.writeAfter()
D.fs.appendFile()
Correct Answer: fs.appendFile()
Explanation:
fs.appendFile() asynchronously appends data to a file, creating the file if it does not yet exist.
Incorrect! Try again.
25How do you delete a file using the 'fs' module?
A.fs.unlink()
B.fs.erase()
C.fs.remove()
D.fs.delete()
Correct Answer: fs.unlink()
Explanation:
fs.unlink() is the method used to delete a file from the filesystem.
Incorrect! Try again.
26Which method converts a JavaScript object into a JSON string?
A.JSON.stringify()
B.JSON.convert()
C.JSON.toString()
D.JSON.parse()
Correct Answer: JSON.stringify()
Explanation:
JSON.stringify() converts a JavaScript object or value to a JSON string.
Incorrect! Try again.
27Which method parses a JSON string into a JavaScript object?
A.JSON.stringify()
B.JSON.parse()
C.JSON.decode()
D.JSON.objectify()
Correct Answer: JSON.parse()
Explanation:
JSON.parse() parses a JSON string, constructing the JavaScript value or object described by the string.
Incorrect! Try again.
28What is a Stream in Node.js?
A.A database connection
B.A continuous flow of data handled piece by piece
C.A large file stored in memory
D.A static HTML page
Correct Answer: A continuous flow of data handled piece by piece
Explanation:
Streams are collections of data that might not be available all at once and don't have to fit in memory. They allow handling data in chunks.
Incorrect! Try again.
29Which type of stream can generally be used to read data from a source?
A.Duplex
B.Readable
C.Transform
D.Writable
Correct Answer: Readable
Explanation:
Readable streams are used for reading data (e.g., fs.createReadStream).
Incorrect! Try again.
30What is the purpose of the 'pipe()' method in streams?
A.To connect a readable stream to a writable stream
B.To pause the stream
C.To convert stream to buffer
D.To delete the stream
Correct Answer: To connect a readable stream to a writable stream
Explanation:
pipe() attaches a Writable stream to a Readable stream, automatically passing data from one to the other.
Incorrect! Try again.
31Which module allows you to work with file paths specifically?
A.fs
B.http
C.url
D.path
Correct Answer: path
Explanation:
The 'path' module provides utilities for working with file and directory paths.
Incorrect! Try again.
32Which Node.js module provides compression and decompression functionality?
A.zlib
B.crypto
C.compress
D.zip
Correct Answer: zlib
Explanation:
The 'zlib' module provides compression functionality implementing Gzip, Deflate/Inflate, and Brotli.
Incorrect! Try again.
33Which function creates a stream that compresses data using Gzip?
A.zlib.compress()
B.zlib.createGzip()
C.zlib.zip()
D.zlib.gzip()
Correct Answer: zlib.createGzip()
Explanation:
zlib.createGzip() creates a Transform stream that compresses input data using Gzip.
Incorrect! Try again.
34What are the three states of a Promise?
A.Pending, Fulfilled, Rejected
B.True, False, Null
C.Start, Stop, Pause
D.Running, Waiting, Dead
Correct Answer: Pending, Fulfilled, Rejected
Explanation:
A Promise is always in one of three states: Pending (initial), Fulfilled (success), or Rejected (failure).
Incorrect! Try again.
35Which method is used to handle the successful resolution of a Promise?
A..done()
B..catch()
C..then()
D..finally()
Correct Answer: .then()
Explanation:
The .then() method takes a callback function that runs when the promise is resolved successfully.
Incorrect! Try again.
36Which method is used to catch errors in a Promise chain?
A..catch()
B..error()
C..then()
D..fail()
Correct Answer: .catch()
Explanation:
The .catch() method is used to handle rejected promises or errors thrown in the promise chain.
Incorrect! Try again.
37What does the 'async' keyword do when placed before a function?
A.It makes the function run in a separate thread
B.It makes the function synchronous
C.It pauses the event loop
D.It ensures the function returns a Promise
Correct Answer: It ensures the function returns a Promise
Explanation:
Async functions always return a promise. If the function returns a value, the promise is resolved with that value.
Incorrect! Try again.
38The 'await' keyword can only be used inside which type of function?
A.async functions
B.Synchronous functions
C.Callback functions
D.Any function
Correct Answer: async functions
Explanation:
The 'await' keyword is valid only inside an async function (or at the top level of modules in newer Node versions).
Incorrect! Try again.
39What is the benefit of using async/await over callbacks?
A.It writes asynchronous code that looks synchronous and is easier to read
B.It runs faster
C.It bypasses the V8 engine
D.It creates multi-threading
Correct Answer: It writes asynchronous code that looks synchronous and is easier to read
Explanation:
Async/await provides syntactic sugar over Promises, avoiding callback hell and making the code flow linear and readable.
Incorrect! Try again.
40What is the global object in Node.js equivalent to 'window' in browsers?
A.document
B.global
C.process
D.root
Correct Answer: global
Explanation:
In Node.js, 'global' is the top-level scope object.
Incorrect! Try again.
41Which global variable holds the directory name of the current module?
A.__filename
B.module.path
C.__dirname
D.process.cwd()
Correct Answer: __dirname
Explanation:
__dirname is a local variable in each module that contains the absolute path to the directory containing the current file.
Incorrect! Try again.
42Which method checks if a file exists in Node.js (Modern approach)?
A.fs.check()
B.fs.validate()
C.fs.exists()
D.fs.access()
Correct Answer: fs.access()
Explanation:
fs.access() is the recommended way to check for file accessibility/existence. fs.exists() is deprecated.
Incorrect! Try again.
43What is a 'Duplex' stream?
A.A stream that can only read
B.A stream that can only write
C.A stream that can both read and write
D.A stream that compresses data
Correct Answer: A stream that can both read and write
Explanation:
Duplex streams implement both the Readable and Writable interfaces (e.g., TCP sockets).
Incorrect! Try again.
44What is the file extension typically used for a file containing CommonJS module code?
A..mjs
B..js
C..ts
D..json
Correct Answer: .js
Explanation:
Standard Node.js files using CommonJS use the .js extension.
Incorrect! Try again.
45How can you install a package globally using npm?
A.npm install package --all
B.npm global install package
C.npm install package -g
D.npm add package global
Correct Answer: npm install package -g
Explanation:
The -g flag tells npm to install the package globally so it can be used as a command-line tool.
Incorrect! Try again.
46What does 'npm' stand for?
A.Node Process Manager
B.Node Package Manager
C.Node Project Manager
D.New Package Module
Correct Answer: Node Package Manager
Explanation:
npm is the standard package manager for Node.js.
Incorrect! Try again.
47When using 'fs.createReadStream', which event is fired when the file is completely read?
A.close
B.finish
C.end
D.done
Correct Answer: end
Explanation:
The 'end' event is emitted when there is no more data to be consumed from the readable stream.
Incorrect! Try again.
48In a Promise, what happens if you return a value in a .then() block?
A.The value is ignored
B.It throws an error
C.The promise chain stops
D.The next .then() receives it as a resolved value
Correct Answer: The next .then() receives it as a resolved value
Explanation:
Returning a value in a .then() handler passes that value to the next .then() in the chain.
Incorrect! Try again.
49What is the main advantage of Streams over reading files into memory?
A.Streams are synchronous
B.Streams sort data automatically
C.Streams encrypt data automatically
D.Streams use less memory (memory efficiency)
Correct Answer: Streams use less memory (memory efficiency)
Explanation:
Streams process data chunk by chunk, meaning the whole file doesn't need to be loaded into RAM at once.
Incorrect! Try again.
50Which core module allows you to create a web server?
A.http
B.url
C.fs
D.net
Correct Answer: http
Explanation:
The 'http' module is used to create HTTP servers and clients in Node.js.