Node.js lets JavaScript run outside the browser — on servers, build tools and command-line apps. Under the hood it's Chrome's V8 engine plus a library for talking to the operating system: files, networks, processes. If you did the JavaScript course, you already know the language; Node is where you use it to build back-ends and tools.
What is Node.js?
Node is event-driven and non-blocking. Instead of waiting for a slow operation (a database query, a file read) it starts the task and moves on, running your callback when the result is ready. That's why a single Node process can handle thousands of concurrent connections — ideal for APIs and real-time apps.
Running scripts
Create a file and run it with the node command:
console.log("Hello from Node!");console.log("Args:", process.argv.slice(2)); // command-line arguments
node --version # check it's installednode hello.js # run the scriptnode hello.js one two # pass arguments
The global process object exposes the environment: process.argv (arguments), process.env (environment variables), and process.exit().
Modules
A module is a file. Modern Node uses ES modules (import/export) — enable them by setting "type": "module" in package.json. You'll still meet the older CommonJS (require/module.exports) in many projects:
// math.js — export functionsexport function add(a, b) { return a + b; }export const PI = 3.14159;// app.js — import themimport { add, PI } from "./math.js";console.log(add(2, 3)); // 5
| Style | Export | Import |
|---|---|---|
| ES modules | export | import x from "…" |
| CommonJS | module.exports | const x = require("…") |
npm & packages
npm is Node's package manager and the largest software registry in the world. Initialise a project, then install dependencies:
npm init -y # create package.jsonnpm install express # add a dependencynpm install -D nodemon # dev-only dependencynpm run dev # run a script defined in package.json
Practice
Create a project with npm init -y. Write a greet.js that reads a name from the command-line arguments and prints a greeting. Add a "start" script to package.json and run it with npm start.
Key takeaways
- 01Node.js runs JavaScript outside the browser using V8 + OS bindings.
- 02It is event-driven and non-blocking — great for I/O-heavy servers and APIs.
- 03Run files with node file.js; the process object exposes argv, env and exit.
- 04A module is a file; prefer ES modules (import/export) but recognise CommonJS (require).
- 05npm manages dependencies via package.json; never commit node_modules.
