Node.js lesson · 28 min
Node.js Runtime Basics
Install-check Node.js, run your first script, and understand what changes outside the browser.
What you will practice
- Check that Node.js and npm are installed.
- Create and run a real `.js` file from the terminal.
- Use Node-only globals such as `process.cwd()` and `process.argv`.
What this means
JavaScript is the language. Node.js is a runtime: a program that runs JavaScript outside the browser.
In the browser you usually work with pages, buttons, forms, `document`, and `window`. In Node.js you usually work with files, terminal arguments, packages, environment variables, network sockets, and server processes.
A beginner should start with the real workflow: create a file, run `node file.js`, read the terminal output, change the file, and run it again.
If this is your first time seeing this
Node.js is a real program you run from the terminal.
Start by creating files and running `node file.js`; that is the basic Node.js workflow.
Mini glossary
- Runtime
- The environment that executes code and provides built-in abilities.
- Server-side
- Code that runs on a server or local machine, not inside the user's page.
- DOM
- Browser page APIs that Node.js does not provide by default.
Example from everyday life
The same JavaScript knowledge is like knowing how to drive. The browser is a city car with a dashboard and buttons; Node.js is a work van with storage, tools, and access to the workshop.
How it works step by step
- Run `node -v` to check the Node.js runtime version.
- Run `npm -v` to check that the package manager is available.
- Create `hello-node.js` and run it with `node hello-node.js`.
- Change the script and run the command again. This edit-run-read loop is the foundation of Node.js learning.
Where you will use this
- A Node.js script converts files or generates reports.
- A backend API receives requests from a website or mobile app.
- A build tool compiles, bundles, tests, or checks frontend code.
Before you run the code
These examples are intentionally pure Node.js. They do not use Express, Next.js, TypeScript, Babel, or any framework.
Run them in your terminal. The browser runner is disabled here because real Node.js APIs should run in Node.js, not in a web page.
Run it locally
These examples are meant for a local Node.js project. Create the files shown below, then run the terminal commands from the project folder.
Check your installation
node -v
npm -vCreate a folder and script
mkdir lumio-node-start
cd lumio-node-start
touch hello-node.jsFirst Node.js file
hello-node.jsconst name = process.argv[2] || "student";
console.log(`Hello from Node.js, ${name}!`);
console.log(`Current folder: ${process.cwd()}`);
console.log(`Node version: ${process.version}`);Run it
node hello-node.js
node hello-node.js MiraCommon beginner mistakes
- Expecting `document` or `window` to exist in Node.js.
- Thinking Node.js is a different language from JavaScript.
- Running untrusted code on a server without isolation.
Why there is no browser runner here
This lesson uses real Node.js APIs and terminal commands. Run the examples locally with Node.js so you learn the same workflow used in actual backend projects.
Try changing this next
- Run `node hello-node.js Sasha` with a different name.
- Add `console.log(process.argv)` and inspect the terminal output.
- Run the file from a different folder and compare `process.cwd()`.