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 startedRunning and packages
| What | How |
|---|---|
| Run a file | node app.js |
| Install a package | npm install express |
| Dev only | npm install -D vitest |
| Script | npm run dev |
Code
| What | How |
|---|---|
| In parallel | await Promise.all([a(), b()]) |
| Read a file | await readFile(file, "utf8") |
| Path | path.join(dir, "app.json") |
| Event | emitter.on("paid", fn) |
Process, server, tests
| What | How |
|---|---|
| Environment from a file | node --env-file=.env app.js |
| Error code | process.exitCode = 1 |
| The server | createServer((req, res) => res.end("ok")).listen(3000) |
| Streams | await pipeline(src, createGzip(), dest) |
| Cause | throw new Error("…", { cause: err }) |
| Tests | node --test |