What Node.js Is
💻 Node.jsUnderstand how Node runs JavaScript outside the browser and why non-blocking I/O matters.
Node.js is a JavaScript runtime built on Chrome's V8 engine. It runs your code on a server, a laptop or a small device, without a browser.
- Explain the event loop.
- Run a script with node.
- Describe blocking versus non-blocking work.
Run a Script
Install Node from nodejs.org, then run any JavaScript file directly.
node --version
node app.jsThe Event Loop
Node runs JavaScript on one thread. Slow work such as file or network access is handed to the system and resumed later through callbacks. This is why a single Node process can handle many connections.
Blocking vs Non-Blocking
A heavy loop blocks everything else. Reading a file asynchronously frees the process to handle other requests while it waits.
import { readFile } from "node:fs/promises";
// Non-blocking: other work can run while this waits
const text = await readFile("notes.txt", "utf8");
console.log(text);Practice
- Run node --version and print the result.
- Write a script that prints the current time.
- Explain why a long loop is dangerous in a web server.
Hands-on exercise
Create app.js that:
1. Prints 'Node is running'.
2. Prints the current year using new Date().getFullYear().
3. Run it with node app.js.
Recap
Node runs JavaScript outside the browser. Non-blocking I/O and the event loop let one process serve many clients.
Example
node --version
node app.js
Exercises
1. Prints 'Node is running'.
2. Prints the current year using new Date().getFullYear().
3. Run it with node app.js.
Expected Output
Node is running
2026