Node.js flashcards
JavaScript on the server, files and the network.
Beginner friendly, starts from zero
0
Node.js at a glance
Node.js lets you run JavaScript on your computer or a server, not only inside a web page.
JavaScript is a cook; Node gives him his own kitchen where the fridge (files) and phone (network) are unlocked.
Words you will meet
- Server
- A computer that waits for requests and answers them
- Terminal
- A text window where you type commands
- Module
- A JavaScript file that shares code with other files
- Package
- Ready-made code someone shared for you to install
- npm
- The tool that downloads and manages packages
- Async
- Start a slow job and carry on without waiting
- Event loop
- The part of Node that picks up each finished job
- LTS
- A Node version that gets fixes for a long time
The steps
- 1. Start from zero (12 cards): What Node is, the words you need, and your first script in the terminal.
- 2. Core basics (16 cards): Running files, modules, npm, files, env vars and the built-in tools you get for free.
- 3. Next steps (16 cards): The event loop, HTTP, streams, errors, testing and dependency hygiene.
- 4. Go deeper (16 cards): libuv internals, threads, backpressure, observability, security and production operations.
All 12 cards in Start from zero
- What is Node.js, in one plain sentence?
- Node.js is a program that lets you run JavaScript on your own computer or on a server, not only inside a web page.
- Before Node, what was the problem for web builders?
- JavaScript only ran inside browsers, so the code behind a website, which stores accounts and sends pages, had to be written in a different language. Node let one language do both sides.
- Where might you already meet Node in daily life?
- Many online shops, chat apps and streaming sites answer your clicks with Node running on their servers. Many coding tools that developers use every day also run on Node.
- What everyday picture fits Node best?
- JavaScript is a cook. A browser is a restaurant kitchen with locked cupboards, for safety. Node gives the same cook his own kitchen, with the fridge (your files) and the phone (the network) unlocked.
- What do 'browser', 'server' and 'program' mean?
- A browser is the app you open websites in, like Chrome. A server is a computer that waits for requests and answers them, like sending a web page. A program is a set of instructions a computer runs.
- What are a 'terminal' and a 'command'?
- A terminal is a text window where you type commands instead of clicking. A command like
node -vtells the computer to run a program; this one prints which Node version you have, such asv24.11.0. - What do 'module', 'import' and 'export' mean?
- A module is one JavaScript file that shares some of its code.
exportmarks what it shares, andimportpulls it into another file. Node also has built-in modules, likenode:fsfor files. - What are a 'package', 'npm' and
package.json? - A package is ready-made code someone shared, like a date formatter. npm is the tool and online store that downloads packages into a
node_modulesfolder.package.jsonlists your project's name, packages and scripts. - What do 'blocking', 'async', 'await' and 'event loop' mean?
- Reading a file or calling a website takes time. Blocking code makes everything wait; async code starts the job and moves on, and
awaitwaits for its result without freezing the rest. The event loop is the part of Node that picks up each finished job. - What do you need before starting this topic?
- A computer with Windows, macOS or Linux, a text editor, and Node installed from its official site; pick the LTS (long-term support) version. Knowing basic JavaScript helps a lot.
- Your first tiny win: what happens when you run this file?
- Save it as
hello.js, then typenode hello.jsin the terminal.console.logprints a line, so you see the greeting with no browser at all. - What will you be able to do after this topic?
- Run scripts, read and write files, call web APIs, build a small web server, and use packages safely, with a clear picture of how Node handles many jobs at once.
Node.js cheatsheet
Run flags
node --watch server.jsRestart on file changenode --env-file=.env app.jsLoad env vars from a filenode app.tsRun TypeScript (types stripped)node --test --watchRun tests on changenode --inspect-brk app.jsDebugger, paused on line 1node --cpu-prof app.jsWrite a CPU profilenode --max-old-space-size=3072Heap limit in MBnode --permission --allow-fs-read=.Restrict file and process accessnode --run buildRun apackage.jsonscript, fast
npm
npm ciClean, exact install from lock filenpm ci --omit=devProduction installnpm i -D vitestAdd a dev dependencynpm ls reactWhy is this version installednpm outdatedList available updatesnpm audit --omit=devKnown vulnerabilities in runtime depsnpm pkg set scripts.lint="eslint ."Editpackage.jsonfrom the shellnpm exec -- tsc --noEmitRun a local binary
Core modules
node:fs/promisesreadFile,writeFile,mkdir,watchnode:stream/promisespipelinewith cleanupnode:pathjoin,resolve,extnamenode:cryptorandomUUID,createHmac,timingSafeEqualnode:worker_threadsCPU work off the main threadnode:child_processspawn,execFilenode:async_hooksAsyncLocalStoragenode:utilparseArgs,styleText,promisifynode:sqliteBuilt-in SQLite (experimental)
Event loop order
sync codeRuns to completion firstprocess.nextTick(fn)Before promises, same turnqueueMicrotask(fn) / .thenMicrotasks, same turnsetTimeout(fn, 0)Timers phase, next turnI/O callbacksPoll phasesetImmediate(fn)Check phase, right after poll
Production globals
AbortSignal.timeout(5000)Cancel after 5 sAbortSignal.any([a, b])Cancel on either signalstructuredClone(order)Deep copyimport.meta.dirnameFolder of this moduleprocess.loadEnvFile()Load.envin codeprocess.memoryUsage()rss,heapUsed,externalprocess.on("SIGTERM", fn)Graceful shutdown hook