Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
You're offline
Unit 1 MCQsGetting Started with Node.JS & Handling Data I/O in Node.js
Node.js is built on Chrome's V8 JavaScript engine, which compiles JavaScript directly to native machine code.
Question 2 of 50
Which of the following best describes the nature of Node.js?
Not quite. Try another option.
Answer: Single-threaded and non-blocking
Node.js uses a single-threaded event loop architecture but handles I/O operations asynchronously (non-blocking).
Question 3 of 50
Who created Node.js?
Not quite. Try another option.
Answer: Ryan Dahl
Ryan Dahl created Node.js in 2009.
Question 4 of 50
What does REPL stand for in the context of Node.js?
Not quite. Try another option.
Answer: Read Eval Print Loop
REPL stands for Read Eval Print Loop, an interactive shell that processes Node.js expressions.
Question 5 of 50
Which command allows you to enter the Node.js REPL environment in a terminal?
Not quite. Try another option.
Answer: node
Typing 'node' in the command prompt without arguments starts the REPL session.
Question 6 of 50
In the Node.js REPL, what does the underscore variable (_) represent?
Not quite. Try another option.
Answer: The last evaluated result
The underscore (_) serves as a special variable that stores the result of the previously executed expression.
Question 7 of 50
Which command is used to initialize a new Node.js project and create a package.json file?
Not quite. Try another option.
Answer: npm init
The 'npm init' command guides you through creating a package.json file for your project.
Question 8 of 50
Which flag can be used with 'npm init' to skip the questionnaire and use default values?
Not quite. Try another option.
Answer: -y
The '-y' (or --yes) flag skips the interactive questions and creates a package.json with default settings.
Question 9 of 50
Where does npm install the dependencies for a local project by default?
Not quite. Try another option.
Answer: node_modules
npm installs local dependencies in a folder named 'node_modules' within the project root.
Question 10 of 50
Which file stores the metadata and dependency list for a Node.js project?
Not quite. Try another option.
Answer: package.json
The package.json file holds metadata relevant to the project, including dependencies, scripts, and version info.
Question 11 of 50
Which function is used to include modules in Node.js?
Not quite. Try another option.
Answer: require()
In CommonJS (default Node.js module system), 'require()' is used to load modules.
Question 12 of 50
Which of the following is a Core Module in Node.js?
Not quite. Try another option.
Answer: fs
'fs' (File System) is a built-in core module in Node.js. The others are third-party modules.
Question 13 of 50
How do you export a function or object from a module in Node.js using CommonJS?
Not quite. Try another option.
Answer: module.exports
The 'module.exports' object is used to define what a module exposes to other files using 'require'.
Question 14 of 50
Which syntax is correct to import a local module located in the same directory?
Not quite. Try another option.
Answer: require('./moduleName')
Local modules must be prefixed with './' (or '../' for parent directories) to distinguish them from core or node_modules.
Question 15 of 50
What is the purpose of the 'events' module in Node.js?
Not quite. Try another option.
Answer: To handle and trigger events
The 'events' module allows objects (EventEmitters) to emit named events that cause Function objects (listeners) to be called.
Question 16 of 50
Which class is the primary component of the 'events' module?
Not quite. Try another option.
Answer: EventEmitter
The EventEmitter class is the core of the events module.
Question 17 of 50
Which method of EventEmitter is used to register a listener for an event?
Not quite. Try another option.
Answer: on()
The 'on()' method is used to register a callback function (listener) that executes when a specific event is emitted.
Question 18 of 50
Which method of EventEmitter causes an event to occur?
Not quite. Try another option.
Answer: emit()
The 'emit()' method triggers the event, causing all registered listeners to execute.
Question 19 of 50
What is a 'callback' in Node.js?
Not quite. Try another option.
Answer: A function passed as an argument to be executed later
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.
Question 20 of 50
What is the convention for the first argument of a Node.js callback function?
Not quite. Try another option.
Answer: The error object (or null)
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.
Question 21 of 50
What is 'Callback Hell'?
Not quite. Try another option.
Answer: Deeply nested callbacks making code hard to read
Callback Hell (or Pyramid of Doom) refers to heavily nested callback functions that make code difficult to maintain and debug.
Question 22 of 50
Which method is used to read a file asynchronously in Node.js?
Not quite. Try another option.
Answer: fs.readFile()
fs.readFile() reads the entire contents of a file asynchronously.
Question 23 of 50
What happens if you use 'fs.writeFile()' on an existing file?
Not quite. Try another option.
Answer: It replaces the file content
fs.writeFile() overwrites the file if it already exists.
Question 24 of 50
Which 'fs' method is used to add data to a file without overwriting it?
Not quite. Try another option.
Answer: fs.appendFile()
fs.appendFile() asynchronously appends data to a file, creating the file if it does not yet exist.
Question 25 of 50
How do you delete a file using the 'fs' module?
Not quite. Try another option.
Answer: fs.unlink()
fs.unlink() is the method used to delete a file from the filesystem.
Question 26 of 50
Which method converts a JavaScript object into a JSON string?
Not quite. Try another option.
Answer: JSON.stringify()
JSON.stringify() converts a JavaScript object or value to a JSON string.
Question 27 of 50
Which method parses a JSON string into a JavaScript object?
Not quite. Try another option.
Answer: JSON.parse()
JSON.parse() parses a JSON string, constructing the JavaScript value or object described by the string.
Question 28 of 50
What is a Stream in Node.js?
Not quite. Try another option.
Answer: A continuous flow of data handled piece by piece
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.
Question 29 of 50
Which type of stream can generally be used to read data from a source?
Not quite. Try another option.
Answer: Readable
Readable streams are used for reading data (e.g., fs.createReadStream).
Question 30 of 50
What is the purpose of the 'pipe()' method in streams?
Not quite. Try another option.
Answer: To connect a readable stream to a writable stream
pipe() attaches a Writable stream to a Readable stream, automatically passing data from one to the other.
Question 31 of 50
Which module allows you to work with file paths specifically?
Not quite. Try another option.
Answer: path
The 'path' module provides utilities for working with file and directory paths.
Question 32 of 50
Which Node.js module provides compression and decompression functionality?
Not quite. Try another option.
Answer: zlib
The 'zlib' module provides compression functionality implementing Gzip, Deflate/Inflate, and Brotli.
Question 33 of 50
Which function creates a stream that compresses data using Gzip?
Not quite. Try another option.
Answer: zlib.createGzip()
zlib.createGzip() creates a Transform stream that compresses input data using Gzip.
Question 34 of 50
What are the three states of a Promise?
Not quite. Try another option.
Answer: Pending, Fulfilled, Rejected
A Promise is always in one of three states: Pending (initial), Fulfilled (success), or Rejected (failure).
Question 35 of 50
Which method is used to handle the successful resolution of a Promise?
Not quite. Try another option.
Answer: .then()
The .then() method takes a callback function that runs when the promise is resolved successfully.
Question 36 of 50
Which method is used to catch errors in a Promise chain?
Not quite. Try another option.
Answer: .catch()
The .catch() method is used to handle rejected promises or errors thrown in the promise chain.
Question 37 of 50
What does the 'async' keyword do when placed before a function?
Not quite. Try another option.
Answer: It ensures the function returns a Promise
Async functions always return a promise. If the function returns a value, the promise is resolved with that value.
Question 38 of 50
The 'await' keyword can only be used inside which type of function?
Not quite. Try another option.
Answer: async functions
The 'await' keyword is valid only inside an async function (or at the top level of modules in newer Node versions).
Question 39 of 50
What is the benefit of using async/await over callbacks?
Not quite. Try another option.
Answer: It writes asynchronous code that looks synchronous and is easier to read
Async/await provides syntactic sugar over Promises, avoiding callback hell and making the code flow linear and readable.
Question 40 of 50
What is the global object in Node.js equivalent to 'window' in browsers?
Not quite. Try another option.
Answer: global
In Node.js, 'global' is the top-level scope object.
Question 41 of 50
Which global variable holds the directory name of the current module?
Not quite. Try another option.
Answer: __dirname
__dirname is a local variable in each module that contains the absolute path to the directory containing the current file.
Question 42 of 50
Which method checks if a file exists in Node.js (Modern approach)?
Not quite. Try another option.
Answer: fs.access()
fs.access() is the recommended way to check for file accessibility/existence. fs.exists() is deprecated.
Question 43 of 50
What is a 'Duplex' stream?
Not quite. Try another option.
Answer: A stream that can both read and write
Duplex streams implement both the Readable and Writable interfaces (e.g., TCP sockets).
Question 44 of 50
What is the file extension typically used for a file containing CommonJS module code?
Not quite. Try another option.
Answer: .js
Standard Node.js files using CommonJS use the .js extension.
Question 45 of 50
How can you install a package globally using npm?
Not quite. Try another option.
Answer: npm install package -g
The -g flag tells npm to install the package globally so it can be used as a command-line tool.
Question 46 of 50
What does 'npm' stand for?
Not quite. Try another option.
Answer: Node Package Manager
npm is the standard package manager for Node.js.
Question 47 of 50
When using 'fs.createReadStream', which event is fired when the file is completely read?
Not quite. Try another option.
Answer: end
The 'end' event is emitted when there is no more data to be consumed from the readable stream.
Question 48 of 50
In a Promise, what happens if you return a value in a .then() block?
Not quite. Try another option.
Answer: The next .then() receives it as a resolved value
Returning a value in a .then() handler passes that value to the next .then() in the chain.
Question 49 of 50
What is the main advantage of Streams over reading files into memory?
Not quite. Try another option.
Answer: Streams use less memory (memory efficiency)
Streams process data chunk by chunk, meaning the whole file doesn't need to be loaded into RAM at once.
Question 50 of 50
Which core module allows you to create a web server?
Not quite. Try another option.
Answer: http
The 'http' module is used to create HTTP servers and clients in Node.js.
That's unit 1
Answer a few questions and your score shows up here.
Nearly through. Did unit 1 of INT222 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 1 of INT222 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.