Explanation: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.Multi-threaded and blocking
B.Single-threaded and non-blocking
C.Multi-threaded and non-blocking
D.Single-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.Brendan Eich
B.Ryan Dahl
C.Jordan Walke
D.Tim Berners-Lee
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 Eval Print Loop
D.Read Execute Process List
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.npm start
B.node
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 global scope
B.The last evaluated result
C.The current directory
D.An undefined variable
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 new
C.npm start
D.npm init
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.--skip
B.-y
C.--default
D.-f
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.global_modules
C.node_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.index.js
B.package.json
C.config.xml
D.node_modules
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.include()
B.import()
C.require()
D.fetch()
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.fs
C.lodash
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.export default
B.module.exports
C.exports.module
D.return 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.require('moduleName')
B.require('./moduleName')
C.require('/moduleName')
D.import 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 file operations
B.To handle HTTP requests
C.To handle and trigger events
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.EventDispatcher
B.EventListener
C.EventEmitter
D.EventHandler
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.emit()
B.on()
C.trigger()
D.listen()
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.emit()
C.fire()
D.call()
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.A syntax error in callbacks
B.Deeply nested callbacks making code hard to read
C.When a callback never executes
D.A security vulnerability
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.read()
B.fs.readFileSync()
C.fs.readFile()
D.fs.open()
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 throws an error
B.It appends data to the end
C.It replaces the file content
D.It creates a backup copy
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.addFile()
B.fs.writeAfter()
C.fs.appendFile()
D.fs.insert()
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.delete()
B.fs.remove()
C.fs.unlink()
D.fs.erase()
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.parse()
B.JSON.stringify()
C.JSON.convert()
D.JSON.toString()
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.parse()
B.JSON.stringify()
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 continuous flow of data handled piece by piece
B.A database connection
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.Writable
B.Readable
C.Duplex
D.Transform
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 delete the stream
B.To pause the stream
C.To connect a readable stream to a writable stream
D.To convert stream to buffer
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.path
C.url
D.http
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?