Node JS Assignment- 1
Basic Questions
- Write a Node.js script that prints the current file name and directory path using __filename and __dirname.
- Write a Node.js script that reads the command‑line argument (your name) and prints “Hello, <name>”.
- Write a Node.js script that prints process uptime in seconds using process.uptime().
- Write a Node.js script that prints Node.js versions of V8 and OpenSSL from process.versions.
- Write a Node.js script that demonstrates using setTimeout and setImmediate together to show their execution order.
- Write a Node.js script that prints “Hello, Node.js!”.
- Use console.log to print “Node.js Basics Assignment” five times.
- Print the current working directory using process.cwd().
- Print the platform (process.platform) your Node.js is running on.
- Print the architecture (process.arch) your Node.js is using.
- Log the Node.js runtime version using process.version.
- Print all environment variables using process.env.
- Print the global object in Node.js.
- Create a script that prints “Script executed at: <current time>”.
- Use console.error to print “This is an error message”.
- Use console.warn to print a warning message.
- Write a script that prints “Node.js event-driven” using setTimeout.
- Create a simple script that prints command-line arguments using process.argv.
- Create a script that prints “Node.js assignment completed” every 2 seconds using setInterval.
- Exit a Node.js script after printing “Exiting program” using process.exit().
Intermediate Questions
- Create a script that prints “Hello, <name>!” using a command-line argument.
- Write a script that calculates the sum of two numbers passed via command-line arguments.
- Create a Node.js script that uses setTimeout to print “Task 1 complete” after 3 seconds.
- Create a script that prints numbers 1 to 5 using a non-blocking loop with setTimeout.
- Write a Node.js program to print the current date and time using Date object.
- Create a script to compare process.argv.length with process.argv output.
- Write a script that prints “Event loop demo” in the correct asynchronous order using setImmediate and setTimeout.
- Write a Node.js script that uses process.memoryUsage() and prints total/used memory in MB.
- Write a Node.js script that takes two numbers from command‑line arguments and prints their product.
- Write a Node.js script that creates a timer which prints “Working…” every 1 second and stops after 5 seconds.
- Print the platform and architecture in one message like “Running on <platform>-<arch>”.
- Write a script that prints the type of process object.
- Print the memory usage of a Node.js process using process.memoryUsage().
- Use a command-line argument to take a number n and print numbers 1 to n.
- Write a script that prints “Non-blocking example” along with the elapsed time using console.time and console.timeEnd.
- Write a Node.js script that prints the first 5 environment variables using process.env.
- Create a script that prints “Learning Node.js Event Loop” after a 2-second delay using setTimeout.
- Create a simple timer using setInterval that prints “Tick” every second for 5 seconds.
- Write a script that prints all process methods available in Node.js.
- Write a Node.js script that prints the current working directory every 2 seconds and stops after 3 times.
Advanced Questions
- Demonstrate event-driven architecture: create a simple EventEmitter and trigger a custom event “taskCompleted”.
- Write a script to demonstrate single-threaded event loop by running multiple asynchronous tasks and logging execution order.
- Compare blocking vs non-blocking I/O: read a file using fs.readFileSync and fs.readFile and log execution times.
- Write a Node.js script that creates an EventEmitter with two custom events (startTask, endTask) and handles them.
- Demonstrate asynchronous behavior using nested setTimeout calls.
- Create a script that prints environment variables only if a specific variable DEBUG=true is set.
- Write a Node.js script that simulates a simple backend workflow using asynchronous tasks (setTimeout) and logs progress.
- Implement a script that uses process.argv to take a filename as input and prints “Processing <filename>…”.
- Write a Node.js script that demonstrates async vs sync file read using fs.readFile and fs.readFileSync.
- Write a Node.js script that starts three asynchronous timers (setTimeout) with different delays and logs their completion times.