Node.js Basics

JavaScript… outside the browser? Illegal. (It’s legal.)

▶ the lesson · narrated sketch video · tap for sound

the intro

Node.js runs JavaScript on your machine and on servers. You get the language you already know plus modules, npm packages, and access to files and networks. Most backend JavaScript jobs are Node jobs, so this is the on-ramp.

fun fact ✦

Node.js shipped in 2009 and made “JavaScript everywhere” real.

the docs

the deep dive

the ideas behind the video — concepts, diagrams, a walkthrough and the traps to avoid

Node is the browser talked out of the way. It takes V8, the same JavaScript engine Chrome uses, and swaps the page for the operating system: files to read, networks to listen on, processes to run. You write the language you already know and just get different superpowers.

same language, new superpowers

app.jsV8 enginefiles + net
plain JavaScript in, operating-system powers out

key terms

runtime

The program that executes your code. The browser is one runtime; Node is another for the same language.

node app.js

npm

The package registry and tool that ships with Node. A million libraries, one install command away.

npm install express

module

One file of code you can import into another. Node ships built-ins like fs and http, no install needed.

import fs from "node:fs"

package.json

The ID card of a project: name, dependencies, and the scripts that run it.

npm run dev

how it works

  1. 1
    Install the LTS

    Grab the Long Term Support version from nodejs.org. It is the stable one teams actually run.

  2. 2
    Start a project

    npm init creates package.json, the file that tracks dependencies and scripts.

  3. 3
    Write and run

    Put code in app.js and type node app.js. No browser, no build step, it just executes.

  4. 4
    Iterate with --watch

    node --watch app.js restarts on every save. Built in since Node 18, so retire nodemon.

the code, explained

things no browser JavaScript can do

1// run me: node app.js ericko
2const name = process.argv[2] ?? 'stranger'
command-line args: the OS hands your script input
3
4console.log(`hello ${name}`)
5console.log('node', process.version)
runtime globals, not browser globals

side by side

in Node

  • reads and writes files
  • listens on ports
  • no window, no document
VS

in the browser

  • renders pages with the DOM
  • sandboxed away from your files
  • a tab crash is not your crash
⚠️ watch out

Node runs your code on one thread. One slow synchronous call, a readFileSync or a giant JSON.parse or a sneaky while loop, and every connected user waits behind it. The event loop forgives nothing; keep it moving.

quick answers

Is Node really single-threaded?

Your JavaScript runs on one thread, yes. Node uses others behind the scenes for disk and network I/O, which is why async work does not block. CPU-heavy work does.

Do I have to learn a new language for backend?

No. Same JavaScript or TypeScript. What changes is the library: no DOM, but fs, http, and process instead.

Should I learn Bun or Deno instead?

They are credible and fast, but Node has the deepest ecosystem and the most job listings. Learn Node first; the skills transfer in an afternoon.

quick hits about Node.js Basics

short answers · interviews, tips, trivia & hidden gems

🎤 interview

What is the event loop?watch ↗

🎤 interview

require or import?watch ↗

📚 tutorial

Your package.json is a task runnerwatch ↗

🔧 useful

Config that changes per environment?watch ↗

💎 deep

Test ideas without files?watch ↗

🆕 update

Meet Bunwatch ↗

💎 deep

Stop restarting Node manually?watch ↗