One page

Node.js cheat sheet

What to keep at hand. If a line is not clear, go back to the matching lesson in the course.

Open the course: Node.js: getting started

Running and packages

WhatHow
Run a filenode app.js
Install a packagenpm install express
Dev onlynpm install -D vitest
Scriptnpm run dev

Code

WhatHow
In parallelawait Promise.all([a(), b()])
Read a fileawait readFile(file, "utf8")
Pathpath.join(dir, "app.json")
Eventemitter.on("paid", fn)

Process, server, tests

WhatHow
Environment from a filenode --env-file=.env app.js
Error codeprocess.exitCode = 1
The servercreateServer((req, res) => res.end("ok")).listen(3000)
Streamsawait pipeline(src, createGzip(), dest)
Causethrow new Error("…", { cause: err })
Testsnode --test

Other cheat sheets