Skip to main content
Albero Academy

Node.js Fundamentals

Run JavaScript outside the browser — the runtime, modules, npm, and your first script and package.

Chapter 1Node.js13 min readBeginner friendly
  • #Node.js
  • #Basics
  • #npm

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:

hello.js
console.log("Hello from Node!");
console.log("Args:", process.argv.slice(2)); // command-line arguments
terminal
node --version # check it's installed
node hello.js # run the script
node 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 & app.js
// math.js — export functions
export function add(a, b) { return a + b; }
export const PI = 3.14159;
// app.js — import them
import { add, PI } from "./math.js";
console.log(add(2, 3)); // 5
StyleExportImport
ES modulesexportimport x from "…"
CommonJSmodule.exportsconst x = require("…")

npm & packages

npm is Node's package manager and the largest software registry in the world. Initialise a project, then install dependencies:

terminal
npm init -y # create package.json
npm install express # add a dependency
npm install -D nodemon # dev-only dependency
npm 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

  1. 01Node.js runs JavaScript outside the browser using V8 + OS bindings.
  2. 02It is event-driven and non-blocking — great for I/O-heavy servers and APIs.
  3. 03Run files with node file.js; the process object exposes argv, env and exit.
  4. 04A module is a file; prefer ES modules (import/export) but recognise CommonJS (require).
  5. 05npm manages dependencies via package.json; never commit node_modules.