lecture Notes on Class 1:
Introduction to Node.js
Objective
- Understand the basics of Node.js.
- Learn about its installation process.
- Explore its role in web development.
What is Node.js?
Node.js is an
open-source, cross-platform runtime environment that allows developers to run
JavaScript on the server side. Traditionally, JavaScript was only executed in
the browser, but with Node.js, you can now use JavaScript to build backend
applications.
Key Features of
Node.js:
- Asynchronous and Event-Driven: Handles multiple requests simultaneously
without blocking the thread.
- Fast Execution: Built on Google Chrome's V8 engine,
Node.js is optimized for high performance.
- Single Programming Language: Enables developers to use JavaScript for
both frontend and backend development.
- Extensive Library Support: Includes npm (Node Package Manager) for
easy integration of third-party libraries.
Uses of Node.js:
- Building web servers and APIs.
- Developing real-time applications like
chat apps.
- Creating command-line tools.
- Developing single-page and progressive web
applications.
Installing Node.js
and npm
Steps to Install
Node.js:
- Visit the official Node.js website.
- Download the LTS (Long-Term Support)
version suitable for your operating system (Windows, macOS, Linux).
- Follow the installation instructions
specific to your OS.
Verify
Installation:
- Open your terminal or command prompt.
- Run the following commands to check the
installed versions:
- node -v (to check Node.js version)
- npm -v (to check npm version)
If both commands
return version numbers, the installation was successful.
First Node.js
Program
Creating a Simple
Script
- Open a text editor (e.g., VS Code,
Notepad++).
- Write the following code and save it as app.js:
javascript
CopyEdit
// app.js
console.log("Hello,
World!");
Running the Script
- Open the terminal or command prompt.
- Navigate to the directory where app.js is
saved using the cd command.
- Execute the script using the command:
bash
CopyEdit
node app.js
You should see the
output:
CopyEdit
Hello, World!
Lab Tasks
- Install Node.js and npm:
Follow the steps mentioned in the "Installing Node.js and npm" section. - Verify the Installation:
Run node -v and npm -v in the terminal to confirm successful installation. - Write and Execute a Script:
- Create a file named app.js.
- Write a simple script to print
"Hello, World!" using the instructions provided above.
- Run the script with node app.js.
Conclusion
- Node.js extends JavaScript to the server
side, enabling full-stack development with a single programming language.
- Installing and verifying Node.js and npm
is the first step toward building powerful server-side applications.
- Running a basic script like "Hello,
World!" introduces you to Node.js' environment and execution process.
Next Steps:
In the upcoming classes, we’ll explore how to use Node.js to build web servers
and interact with external libraries using npm.
2/2
You said:
write 10 assignments
from the above concept
ChatGPT said:
ChatGPT
Assignments on
Introduction to Node.js
Assignment 1:
Understanding Node.js
- Research and write a brief essay (300-400
words) on the following:
- What is Node.js?
- Why is Node.js popular in web
development?
- List three real-world applications built
using Node.js.
Assignment 2:
Node.js Installation
- Install Node.js and npm on your computer.
- Write down the step-by-step process you
followed, including screenshots of:
- The download page.
- Successful installation.
- Verification using node -v and npm -v.
Assignment 3: First
Node.js Script
- Write a Node.js script named hello.js that
prints your name, course name, and the message "Welcome to
Node.js!"
- Run the script using the command node
hello.js and share the output.
Assignment 4:
Exploring Node.js Documentation
- Visit the official Node.js documentation.
- Write a summary of the following sections:
- About Node.js
- Features of Node.js
- Commonly used modules (e.g., fs, http).
Assignment 5:
Create and Execute a Custom Script
- Write a Node.js script named info.js that
performs the following:
- Prints the current date and time.
- Prints the name of your operating system.
- Run the script using Node.js and attach
the output.
Assignment 6:
Explore npm Commands
- Use npm to perform the following tasks:
- List globally installed npm packages with
npm list -g.
- Install a simple npm package (e.g., lodash)
globally.
- Write a summary of the npm install, npm
update, and npm uninstall commands.
Assignment 7:
Understanding Asynchronous JavaScript
- Research and explain how Node.js handles
asynchronous operations using the event loop.
- Write a simple asynchronous Node.js script
using setTimeout() that prints:
- "Starting the process..."
- "This message appears after 3
seconds."
Assignment 8:
Create a Node.js Calculator
- Write a Node.js script calculator.js that
performs basic arithmetic operations: addition, subtraction,
multiplication, and division.
- The script should print results for the
following inputs:
- 5 + 10
- 20 - 5
- 4 * 6
- 30 / 5
Assignment 9: Write
and Debug a Node.js Script
- Write a script debug.js with intentional
errors (e.g., missing semicolons or incorrect variable names).
- Debug the errors using the Node.js
terminal and share:
- The original script with errors.
- The corrected script.
- Steps you took to fix the errors.
Assignment 10:
Exploring Node.js Modules
- Research the core modules of Node.js
(e.g., fs, path, os).
- Write a script modules.js that performs
the following:
- Reads and prints the content of a text
file using the fs module.
- Prints the absolute path of the file
using the path module.
- Prints the system architecture using the os
module.
These assignments will
help solidify your understanding of Node.js basics, installation, and its role
in web development.
You said:
write the solutions
for all
ChatGPT said:
ChatGPT
Solutions for
Node.js Assignments
Assignment 1:
Understanding Node.js
Solution:
Write a brief essay covering these points:
- What is Node.js?
- Node.js is an open-source, cross-platform
runtime environment that allows JavaScript to run on the server side. It
uses the V8 engine for fast execution and is designed for building
scalable network applications.
- Why is Node.js popular in web development?
- It allows JavaScript to be used both on
the frontend and backend.
- Non-blocking I/O and event-driven
architecture make it efficient.
- It has a rich ecosystem with npm,
supporting rapid development.
- Examples of real-world applications built
using Node.js:
- Netflix (Streaming Service)
- LinkedIn (Professional Networking)
- Uber (Ride-sharing App)
Assignment 2:
Node.js Installation
Solution:
- Go to Node.js, download the LTS version, and install it.
- Verify the installation:
bash
CopyEdit
node -v # Prints the Node.js version
npm -v # Prints the npm version
- Include screenshots showing the download,
installation, and version verification.
Assignment 3: First
Node.js Script
Script (hello.js):
javascript
CopyEdit
// hello.js
console.log("Name:
John Doe");
console.log("Course:
Web Development");
console.log("Welcome
to Node.js!");
Command to Run:
bash
CopyEdit
node hello.js
Output:
vbnet
CopyEdit
Name: John Doe
Course: Web
Development
Welcome to Node.js!
Assignment 4:
Exploring Node.js Documentation
Solution:
Visit Node.js Documentation.
Summary:
- About Node.js: Node.js is a JavaScript runtime built on
Chrome's V8 engine, designed for scalable network applications.
- Features:
- Event-driven architecture.
- Non-blocking I/O.
- Lightweight and efficient.
- Common Modules:
- fs: File system operations.
- http: Building web servers.
- os: Access system information.
Assignment 5:
Create and Execute a Custom Script
Script (info.js):
javascript
CopyEdit
// info.js
console.log("Current
Date and Time:", new Date().toLocaleString());
console.log("Operating
System:", process.platform);
Command to Run:
bash
CopyEdit
node info.js
Sample Output:
sql
CopyEdit
Current Date and Time:
2025-01-16 10:00:00
Operating System:
win32
Assignment 6:
Explore npm Commands
Solution:
- List globally installed npm packages:
bash
CopyEdit
npm list -g
- Install a package (e.g., lodash):
bash
CopyEdit
npm install -g lodash
- Summary of npm commands:
- npm install: Installs a package.
- npm update: Updates installed packages.
- npm uninstall: Removes a package.
Assignment 7:
Understanding Asynchronous JavaScript
Script (async.js):
javascript
CopyEdit
// async.js
console.log("Starting
the process...");
setTimeout(() => {
console.log("This message appears after
3 seconds.");
}, 3000);
Command to Run:
bash
CopyEdit
node async.js
Output:
arduino
CopyEdit
Starting the
process...
(This message appears
after 3 seconds.)
This message appears
after 3 seconds.
Assignment 8:
Create a Node.js Calculator
Script (calculator.js):
javascript
CopyEdit
// calculator.js
console.log("Addition:
5 + 10 =", 5 + 10);
console.log("Subtraction:
20 - 5 =", 20 - 5);
console.log("Multiplication:
4 * 6 =", 4 * 6);
console.log("Division:
30 / 5 =", 30 / 5);
Command to Run:
bash
CopyEdit
node calculator.js
Output:
makefile
CopyEdit
Addition: 5 + 10 = 15
Subtraction: 20 - 5 =
15
Multiplication: 4 * 6
= 24
Division: 30 / 5 = 6
Assignment 9: Write
and Debug a Node.js Script
Original Script (debug.js)
with Errors:
javascript
CopyEdit
// debug.js
consle.log("Hello,
Debugging"); // Typo in console
let num = 5
console.log("Number:",
num)
Corrected Script (debug.js):
javascript
CopyEdit
// debug.js
console.log("Hello,
Debugging");
let num = 5;
console.log("Number:",
num);
Debugging Steps:
- Run the script:
bash
CopyEdit
node debug.js
- Fix the errors:
- Corrected consle to console.
- Added a semicolon after let num = 5.
Output:
javascript
CopyEdit
Hello, Debugging
Number: 5
Assignment 10:
Exploring Node.js Modules
Script (modules.js):
javascript
CopyEdit
// modules.js
const fs = require("fs");
const path = require("path");
const os = require("os");
// 1. Read and print
the content of a file
fs.writeFileSync("sample.txt",
"Hello, Node.js!");
const data = fs.readFileSync("sample.txt",
"utf8");
console.log("File
Content:", data);
// 2. Print the
absolute path of the file
console.log("File
Path:", path.resolve("sample.txt"));
// 3. Print the system
architecture
console.log("System
Architecture:", os.arch());
Command to Run:
bash
CopyEdit
node modules.js
Output:
mathematica
CopyEdit
File Content: Hello, Node.js!
File Path: /absolute/path/to/sample.txt
System Architecture: x64
These solutions
provide hands-on practice with Node.js basics, strengthening foundational
concepts.
You said:
write 100 MCqs from
the above topic
ChatGPT said:
ChatGPT
Here are 100
multiple-choice questions (MCQs) based on the topic "Introduction to
Node.js."
Basics of Node.js
- What is Node.js primarily used for?
a) Game development
b) Machine learning
c) Server-side scripting
d) Database management
Answer: c) Server-side scripting - Which JavaScript engine does Node.js use?
a) SpiderMonkey
b) Chakra
c) V8
d) JavaScriptCore
Answer: c) V8 - Node.js is built on which programming
language?
a) Python
b) C++
c) Java
d) Ruby
Answer: b) C++ - What kind of architecture does Node.js
use?
a) Thread-based
b) Event-driven, non-blocking I/O
c) Blocking I/O
d) Multi-threaded
Answer: b) Event-driven, non-blocking I/O - Which of the following is NOT a feature of
Node.js?
a) Asynchronous programming
b) Event-driven architecture
c) Blocking I/O
d) Lightweight
Answer: c) Blocking I/O
Node.js
Installation
- Which command is used to check the Node.js
version after installation?
a) node --version
b) node -v
c) npm -v
d) version node
Answer: b) node -v - What does npm stand for?
a) Node.js Programming Module
b) Node Package Manager
c) Non-blocking Process Module
d) Node Processing Manager
Answer: b) Node Package Manager - Which file is required to manage
dependencies in a Node.js project?
a) node_modules.json
b) app.js
c) package.json
d) index.js
Answer: c) package.json - Where can you download Node.js from?
a) nodejs.org
b) npmjs.com
c) node.com
d) github.com/node
Answer: a) nodejs.org - Which command checks the npm version
installed?
a) npm --version
b) npm -v
c) both a and b
d) npm version-check
Answer: c) both a and b
First Node.js
Script
- Which command is used to execute a Node.js
script?
a) run script.js
b) execute script.js
c) node script.js
d) start script.js
Answer: c) node script.js - What will the following script output?
javascript
CopyEdit
console.log("Hello,
Node.js!");
a) Nothing
b) Hello, Node.js!
c) Undefined
d) Error
Answer: b) Hello, Node.js!
- Which extension is used for Node.js files?
a) .node
b) .javascript
c) .js
d) .script
Answer: c) .js - How do you print the current date in
Node.js?
a) console.log(new Date());
b) print(Date.now());
c) console.log(date.today());
d) None of the above
Answer: a) console.log(new Date()); - What will happen if you run an empty
Node.js file?
a) Error
b) It will exit without output
c) Prints "undefined"
d) None of the above
Answer: b) It will exit without output
Core Features
- Which of the following is a core module in
Node.js?
a) express
b) fs
c) mongoose
d) lodash
Answer: b) fs - What does the fs module in Node.js handle?
a) File system operations
b) Networking
c) Database connections
d) HTTP requests
Answer: a) File system operations - Which module is used to create a web
server in Node.js?
a) os
b) http
c) path
d) url
Answer: b) http - How do you import a core module in
Node.js?
a) import moduleName from "module";
b) require("moduleName");
c) include "moduleName";
d) load("moduleName");
Answer: b) require("moduleName"); - Which module is used to interact with the
file system in Node.js?
a) fs
b) path
c) file
d) os
Answer: a) fs
npm Basics
- What does npm install do?
a) Installs the Node.js runtime
b) Installs project dependencies
c) Updates npm version
d) Uninstalls dependencies
Answer: b) Installs project dependencies - How do you install a package globally
using npm?
a) npm install -g packageName
b) npm install --global packageName
c) Both a and b
d) npm add packageName
Answer: c) Both a and b - What is the purpose of the node_modules
folder?
a) To store global npm packages
b) To store project-specific npm packages
c) To store Node.js core modules
d) To store temporary files
Answer: b) To store project-specific npm packages - How do you uninstall a package using npm?
a) npm remove packageName
b) npm uninstall packageName
c) npm delete packageName
d) Both a and b
Answer: b) npm uninstall packageName - What is the package.json file used for?
a) Tracking project dependencies
b) Storing environment variables
c) Managing file system operations
d) Storing logs
Answer: a) Tracking project dependencies
Asynchronous
Programming
- What is the main advantage of asynchronous
programming in Node.js?
a) Faster execution of synchronous tasks
b) Efficient handling of multiple requests
c) Improved code readability
d) Simplified debugging
Answer: b) Efficient handling of multiple requests - What function is used to handle delays in
Node.js?
a) setInterval()
b) setDelay()
c) setTimeout()
d) sleep()
Answer: c) setTimeout() - What does the following code do?
javascript
CopyEdit
setTimeout(() => {
console.log("Hello after 2 seconds");
}, 2000);
a) Prints "Hello
after 2 seconds" immediately
b) Prints "Hello after 2 seconds" after a 2-second delay
c) Throws an error
d) None of the above
Answer: b) Prints "Hello after 2 seconds" after a 2-second
delay
- What is the event loop in Node.js?
a) A loop that handles blocking operations
b) A mechanism for asynchronous execution
c) A way to create HTTP servers
d) A built-in database
Answer: b) A mechanism for asynchronous execution - Which function in Node.js is asynchronous?
a) fs.readFile()
b) console.log()
c) Date.now()
d) Math.random()
Answer: a) fs.readFile()
Would you like me to
continue with the rest?
You said:
yes
ChatGPT said:
ChatGPT
Here are more MCQs to
complete the 100 questions.
Event-Driven
Architecture
- What is the purpose of the Node.js event
loop?
a) To execute blocking operations
b) To handle asynchronous operations
c) To manage database transactions
d) To serve static files
Answer: b) To handle asynchronous operations - In Node.js, events are handled by which
module?
a) events
b) fs
c) eventManager
d) http
Answer: a) events - Which method is used to listen for an
event in Node.js?
a) on()
b) listen()
c) emit()
d) eventHandler()
Answer: a) on() - What does the emit() function do in
Node.js?
a) Emits an event
b) Listens to an event
c) Stops the event loop
d) None of the above
Answer: a) Emits an event - Which of the following best describes an
event in Node.js?
a) A synchronous process
b) A signal that something has happened
c) A function to stop asynchronous tasks
d) None of the above
Answer: b) A signal that something has happened
REPL
(Read-Eval-Print Loop)
- What does REPL stand for in Node.js?
a) Repeat-Evaluate-Print-Loop
b) Read-Eval-Print-Loop
c) Run-Execute-Print-Loop
d) None of the above
Answer: b) Read-Eval-Print-Loop - Which command starts the Node.js REPL?
a) node repl
b) repl start
c) node
d) node start
Answer: c) node - How do you exit the REPL in Node.js?
a) Press Ctrl + D
b) Type .exit
c) Both a and b
d) Press Ctrl + C
Answer: c) Both a and b - Which of the following commands will
display all the available commands in the REPL?
a) .commands
b) help
c) .help
d) .list
Answer: c) .help - What will the REPL output for 2 + 3?
a) 23
b) Error
c) 5
d) None of the above
Answer: c) 5
Node.js Modules
- What are Node.js modules?
a) Files containing multiple programming languages
b) Reusable code libraries
c) Built-in databases
d) Functions that stop the server
Answer: b) Reusable code libraries - Which keyword is used to export a module
in Node.js?
a) import
b) exports
c) require
d) module.exports
Answer: d) module.exports - How do you import a custom module in
Node.js?
a) require('./moduleName');
b) import moduleName from './moduleName';
c) include './moduleName';
d) load('./moduleName');
Answer: a) require('./moduleName'); - Which module is used to work with URLs in
Node.js?
a) fs
b) http
c) url
d) os
Answer: c) url - What does the path module handle in
Node.js?
a) File paths and directories
b) URL parsing
c) HTTP requests
d) Database queries
Answer: a) File paths and directories
Node.js Global
Objects
- What is the __dirname variable in Node.js?
a) Current file name
b) Current working directory
c) Directory name of the current module
d) Node.js installation path
Answer: c) Directory name of the current module - What does process in Node.js represent?
a) Global module for file operations
b) Node.js runtime environment
c) The operating system
d) None of the above
Answer: b) Node.js runtime environment - Which of the following is a global object
in Node.js?
a) setTimeout
b) console
c) process
d) All of the above
Answer: d) All of the above - How do you get the current Node.js version
using process?
a) process.version
b) process.env.NODE_VERSION
c) process.nodeVersion
d) process.getVersion()
Answer: a) process.version - What will console.log(global) output?
a) A list of all global variables and objects
b) The current file path
c) Node.js version
d) None of the above
Answer: a) A list of all global variables and objects
Error Handling
- How does Node.js handle errors in
asynchronous code?
a) Using try-catch blocks
b) By emitting an error event
c) By returning null
d) None of the above
Answer: b) By emitting an error event - What is the default behavior when an error
event is not handled in Node.js?
a) Logs the error and continues
b) Crashes the application
c) Ignores the error
d) Automatically retries
Answer: b) Crashes the application - Which event is emitted when an error
occurs in Node.js?
a) error
b) exception
c) fault
d) warning
Answer: a) error - How do you handle promise rejections in
Node.js?
a) Using try-catch blocks
b) Using .catch()
c) Using process.catch()
d) None of the above
Answer: b) Using .catch() - Which global event handles uncaught
exceptions in Node.js?
a) process.on('error')
b) process.on('uncaughtException')
c) event.on('uncaught')
d) None of the above
Answer: b) process.on('uncaughtException')
Would you like me to
provide the remaining 45 MCQs?
You said:
yes
ChatGPT said:
ChatGPT
Here are the remaining
45 MCQs to complete the set of 100:
Non-Blocking I/O
- What is Non-Blocking I/O in Node.js?
a) Performing input/output operations sequentially
b) Performing input/output operations without blocking the thread
c) Performing synchronous file operations
d) None of the above
Answer: b) Performing input/output operations without blocking the thread - Which of the following makes Node.js ideal
for I/O-intensive applications?
a) Synchronous operations
b) Single-threaded architecture with Non-Blocking I/O
c) Multithreaded architecture
d) None of the above
Answer: b) Single-threaded architecture with Non-Blocking I/O - What does fs.readFile use in Node.js?
a) Blocking I/O
b) Non-Blocking I/O
c) Both a and b
d) None of the above
Answer: b) Non-Blocking I/O - Which callback parameter is usually used
for handling errors in asynchronous functions?
a) The first parameter
b) The second parameter
c) The last parameter
d) None of the above
Answer: a) The first parameter - Which is true about Node.js's
single-threaded architecture?
a) It processes requests one at a time
b) It uses an event loop for concurrent request handling
c) It spawns multiple threads for each request
d) It is not suitable for web applications
Answer: b) It uses an event loop for concurrent request handling
Node.js File System
Module
- Which module is used to work with files in
Node.js?
a) fs
b) file
c) system
d) os
Answer: a) fs - How do you read a file synchronously in
Node.js?
a) fs.readFileSync()
b) fs.readSync()
c) fs.readFile()
d) None of the above
Answer: a) fs.readFileSync() - Which method is used to append data to a
file?
a) fs.append()
b) fs.appendFile()
c) fs.addFile()
d) fs.write()
Answer: b) fs.appendFile() - What does the fs.writeFile() function do?
a) Creates and writes data to a file
b) Appends data to an existing file
c) Reads data from a file
d) Deletes a file
Answer: a) Creates and writes data to a file - What happens if the file specified in fs.unlink()
does not exist?
a) A new file is created
b) An error is thrown
c) It does nothing
d) It returns false
Answer: b) An error is thrown
Node.js HTTP Module
- What is the primary use of the HTTP module
in Node.js?
a) To handle HTTP requests and responses
b) To parse URLs
c) To manage file systems
d) None of the above
Answer: a) To handle HTTP requests and responses - Which method is used to create a server in
Node.js?
a) http.createServer()
b) server.create()
c) http.server()
d) create.httpServer()
Answer: a) http.createServer() - What is the default HTTP port?
a) 3000
b) 8080
c) 80
d) 443
Answer: c) 80 - Which event is emitted when the server
receives a request?
a) request
b) data
c) incoming
d) connect
Answer: a) request - Which method is used to send a response
back to the client?
a) send()
b) end()
c) write()
d) Both b and c
Answer: d) Both b and c
Asynchronous
Programming
- What is a callback in Node.js?
a) A blocking function
b) A function passed as an argument to another function
c) A function that stops execution
d) None of the above
Answer: b) A function passed as an argument to another function - Which statement is true about Promises in
Node.js?
a) They are used for synchronous operations
b) They represent the eventual completion of an asynchronous operation
c) They block the event loop
d) None of the above
Answer: b) They represent the eventual completion of an asynchronous operation - Which of the following methods is used to
handle resolved promises?
a) .catch()
b) .then()
c) .finally()
d) None of the above
Answer: b) .then() - Which of the following is true about
async/await in Node.js?
a) It blocks the main thread
b) It simplifies writing asynchronous code
c) It is synchronous by nature
d) None of the above
Answer: b) It simplifies writing asynchronous code - Which Node.js version introduced
async/await?
a) 6
b) 7
c) 8
d) 10
Answer: c) 8
Node.js NPM (Node
Package Manager)
- What does npm stand for?
a) Node Package Manager
b) Node Program Manager
c) Node Processing Manager
d) None of the above
Answer: a) Node Package Manager - What command is used to initialize a new
Node.js project?
a) npm start
b) npm init
c) npm new
d) npm project
Answer: b) npm init - Which file is created by running npm init?
a) index.js
b) config.json
c) package.json
d) node_modules.json
Answer: c) package.json - How do you install a specific package
using npm?
a) npm install <package_name>
b) npm add <package_name>
c) npm setup <package_name>
d) npm download <package_name>
Answer: a) npm install <package_name> - What does the -g flag do in npm commands?
a) Installs the package globally
b) Uninstalls the package
c) Updates the package
d) None of the above
Answer: a) Installs the package globally
Miscellaneous
- Which of the following is a built-in
Node.js module?
a) os
b) path
c) events
d) All of the above
Answer: d) All of the above - What is the output of console.log('Node.js
is awesome!')?
a) Error
b) Node.js is awesome!
c) node.js IS AWESOME!
d) None of the above
Answer: b) Node.js is awesome! - What is the command to check the Node.js
version?
a) node -v
b) node --version
c) Both a and b
d) None of the above
Answer: c) Both a and b - Which command clears the REPL screen in
Node.js?
a) .clear
b) cls
c) console.clear()
d) Ctrl + L
Answer: d) Ctrl + L - Which method schedules a function to run
after a specified delay?
a) setTimeout()
b) setInterval()
c) runTimeout()
d) delay()
Answer: a) setTimeout()
Would you like me to
continue with the remaining 15?
You said:
yes
ChatGPT said:
ChatGPT
Here are the remaining
15 MCQs:
Miscellaneous
(continued)
- Which method schedules a function to run
repeatedly at a fixed interval?
a) setTimeout()
b) setInterval()
c) repeatTimeout()
d) delayInterval()
Answer: b) setInterval() - What does process.exit() do in Node.js?
a) Exits the application immediately
b) Restarts the application
c) Pauses the application
d) Terminates all processes
Answer: a) Exits the application immediately - Which module is used to parse and format
URLs in Node.js?
a) url
b) path
c) query
d) http
Answer: a) url - Which object provides information about
the current Node.js process?
a) process
b) os
c) system
d) thread
Answer: a) process - What does the __dirname variable
represent?
a) The directory name of the current module
b) The name of the currently executing file
c) The absolute path to the Node.js binary
d) None of the above
Answer: a) The directory name of the current module - Which statement about require() is true?
a) It is used to load built-in modules only
b) It is used to include modules in a Node.js application
c) It blocks the event loop during module loading
d) None of the above
Answer: b) It is used to include modules in a Node.js application - Which of the following is a valid file
extension for a Node.js module?
a) .node
b) .js
c) .json
d) All of the above
Answer: d) All of the above - What does the buffer module in Node.js
provide?
a) Methods for working with binary data
b) Methods for working with strings only
c) Methods for managing processes
d) None of the above
Answer: a) Methods for working with binary data - Which command uninstalls a package using
npm?
a) npm remove <package_name>
b) npm uninstall <package_name>
c) npm delete <package_name>
d) npm erase <package_name>
Answer: b) npm uninstall <package_name> - How can you update a globally installed
package in npm?
a) npm update <package_name> -g
b) npm upgrade <package_name>
c) npm refresh <package_name>
d) npm install <package_name> -u
Answer: a) npm update <package_name> -g
Debugging in
Node.js
- Which command is used to start debugging a
Node.js application?
a) node debug <file_name>
b) node --inspect <file_name>
c) node inspect <file_name>
d) Both b and c
Answer: d) Both b and c - Which tool is commonly used to debug
Node.js applications?
a) Chrome DevTools
b) Firebug
c) Wireshark
d) None of the above
Answer: a) Chrome DevTools - What is the purpose of the console.log()
method?
a) To log errors to a file
b) To print output to the console
c) To send HTTP logs
d) To terminate the program
Answer: b) To print output to the console - Which method pauses execution in Node.js
debugging mode?
a) debug()
b) pause()
c) debugger
d) None of the above
Answer: c) debugger - How can you print stack traces for
debugging in Node.js?
a) console.error()
b) console.stack()
c) console.trace()
d) console.print()
Answer: c) console.trace()

No comments:
Post a Comment