Node.js Tutorial
Run JavaScript on the server to build APIs and tools.
Getting started2 lessons
Basics34 lessons
- 3ModulesCommonJS and ES modules.
- 4npm and package.jsonUse other people's code.
- 5Globals and processprocess, __dirname and arguments.
- 6The console Objectconsole.log writes to standard output, console.error to standard error.
- 7Modern JavaScript in NodeNode supports modern JavaScript: let and const, arrow functions, destructuring, spread, te.
- 8The path Modulepath builds and parses file paths in a cross platform way.
- 9The os Moduleos tells you about the machine: platform, CPU count, memory and the temp folder.
- 10URL and URLSearchParamsThe global URL class parses addresses and URLSearchParams reads and builds query strings.
- 11The util Moduleutil.format builds strings, util.inspect prints objects deeply and util.promisify turns ca.
- 12BuffersA Buffer is a fixed size chunk of raw bytes.
- 13Timers and the Event Loop Orderprocess.nextTick runs before promises, which run before timers.
- 14Environment Variables and Argumentsprocess.env holds environment variables and process.argv holds command line arguments.
- 15Errors and Error CodesWrap risky code in try and catch.
- 16ES Modules and Dynamic ImportUse import and export in .mjs files or when package.json has type module.
- 17npm Scripts and VersionsScripts in package.json run with npm run name.
- 18Running Node.jsRun a file with node file.js.
- 19Variables and TypesNode runs JavaScript.
- 20Functions and ArrowsFunctions are values.
- 21Objects and JSONObjects hold data.
- 22CommonJS Modulesrequire loads a module and module.exports shares values.
- 23ES ModulesFiles ending in .mjs or with "type": "module" use import and export.
- 24Command Line Argumentsprocess.argv lists the arguments.
- 25The process Objectprocess has env, cwd, platform, pid, memoryUsage, uptime and exit.
- 26Environment Variablesprocess.env holds environment variables as strings.
- 27console Methodsconsole has log, error, warn, table, dir, group, time and assert.
- 28Template StringsBackticks allow ${} expressions and multi line text.
- 29Destructuring and SpreadPull values out of objects and arrays and copy or merge with spread.
- 30Array Methodsmap, filter, reduce, find, some, every, sort and flat are the daily tools.
- 31ClassesClasses have constructors and methods.
- 32Callbacks and Error FirstNode callbacks take (err, data).
- 33PromisesA promise stands for a future value.
- 34async and awaitasync functions return promises.
- 35The Event LoopSynchronous code runs first, then microtasks (promises), then timers.
- 36TimerssetTimeout, setInterval and setImmediate schedule work.
Files and events30 lessons
- 37File SystemRead and write files.
- 38EventsEventEmitter.
- 39Callbacks, Promises and async/awaitNon blocking code.
- 40Promises with fs/promisesfs/promises gives promise versions of the file functions, which work well with async and a.
- 41Folders and File Informationmkdir creates folders, readdir lists them, stat returns size and type, and rm removes file.
- 42Streams and pipelineStreams process data in chunks, so a huge file never needs to fit in memory.
- 43Reading Lines with readlinereadline reads a stream one line at a time.
- 44Running Other Programschild_process runs commands.
- 45Hashing and CryptoThe crypto module hashes data, signs messages with HMAC and makes random values.
- 46Compression with zlibzlib compresses and decompresses data with gzip or deflate.
- 47EventEmitter In Depthonce runs a listener a single time, off removes one, and the special error event throws if.
- 48Timers Promises and AbortControllertimers/promises gives awaitable delays.
- 49path Modulepath.join, resolve, basename, extname and dirname build and read file paths without string.
- 50Reading and Writing Filesfs.writeFileSync and readFileSync are simple for small scripts.
- 51fs.promisesfs/promises works with await and never blocks the event loop.
- 52Directoriesmkdir, readdir, stat, rm and cp manage folders.
- 53Checking Filesfs.existsSync tests a path.
- 54EventEmitterEventEmitter lets objects emit named events and listeners react.
- 55Error EventsAn emitter that emits "error" without a listener throws.
- 56BuffersBuffers hold raw bytes.
- 57StreamsStreams process data in chunks.
- 58pipeline and Transformstream.pipeline connects streams and handles errors and cleanup.
- 59readlinereadline reads input line by line.
- 60os Moduleos gives system info: platform, cpus, memory and the temp folder.
- 61URL and URLSearchParamsThe URL class parses addresses and URLSearchParams handles queries.
- 62util Moduleutil.promisify, format, inspect and types help with everyday work.
- 63cryptocrypto makes hashes, random values and UUIDs.
- 64child_processexecSync and spawn run other programs.
- 65zlibzlib compresses data with gzip and deflate.
- 66Worker Threadsworker_threads run JavaScript on another thread for heavy CPU work.
Web with Node33 lessons
- 67HTTP ServerThe built in http module.
- 68JSON and StreamsHandle data in pieces.
- 69HTTP Server and fetch TogetherNode 18 and newer include fetch.
- 70Routing by HandWithout a framework you read req.method and req.url and choose a handler.
- 71A JSON REST HandlerA REST API maps HTTP methods to actions: GET reads, POST creates, PUT updates and DELETE r.
- 72Headers and CookiesHeaders carry metadata.
- 73Configuration and dotenvKeep secrets and settings in environment variables.
- 74Rendering HTMLServers often build HTML from data.
- 75WebSockets and Server Sent EventsWebSockets keep a two way connection open for chat and live updates.
- 76A Basic HTTP Serverhttp.createServer handles requests.
- 77Routing by HandCheck req.method and req.url to decide what to send.
- 78fetch in NodeNode 18+ has fetch built in.
- 79Reading a Request BodyCollect chunks from the request stream, then parse them.
- 80HTTP Status Codes200 OK, 201 Created, 301 Redirect, 400 Bad Request, 401 Unauthorized, 404 Not Found and 50.
- 81Headers and CORSSet headers with setHeader.
- 82CookiesRead Cookie headers and send Set-Cookie.
- 83Serving Static FilesRead a file and send it with the right content type.
- 84Query StringsParse the query with URLSearchParams from req.url.
- 85A JSON APIReturn JSON with the right header and status codes.
- 86Express in One LookExpress wraps http with routing and middleware.
- 87Middleware IdeaMiddleware is a chain of functions where each can change the request or stop it.
- 88Configuration with dotenvKeep settings in .env and load them with dotenv or node --env-file.
- 89npm Commandsnpm init, install, run, update, outdated and ci manage packages.
- 90Semantic VersioningVersions are MAJOR.MINOR.PATCH.
- 91The Built in Test Runnernode:test and node:assert give you tests without extra packages.
- 92assert Moduleassert checks conditions and throws AssertionError when they fail.
- 93Error Types and Custom ErrorsError, TypeError and RangeError are built in.
- 94Uncaught Errorsprocess.on handles uncaughtException and unhandledRejection.
- 95Modern GlobalsNode has fetch, URL, AbortController, structuredClone, TextEncoder and more as globals.
- 96Cancelling with AbortControllerAbortController cancels fetches, timers and streams that accept a signal.
- 97Practice: Group and CountUse reduce to build a frequency map.
- 98Practice: A Tiny CLIParse arguments and print results.
- 99Practice: Log File SummaryRead a file, split lines and count levels.
Advanced Node.jsPremium13 lessons
- 100Express and REST APIsThe most popular framework.
- 101Testing with node:testBuilt in test runner.
- 102Worker Threads and PerformanceUse more than one core.
- 103Security and DeploymentShip safely.
- 104Transform StreamsA Transform stream changes data as it flows through.
- 105AsyncLocalStorageAsyncLocalStorage keeps context, such as a request id, across async calls without passing .
- 106Measuring Performanceperformance.now measures elapsed time.
- 107Assertions with node:assertassert checks values and throws on failure.
- 108Built in SQLiteNode 22.5+ includes node:sqlite so small apps need no database server.
- 109Modern GlobalsNode includes web style globals: fetch, structuredClone, TextEncoder, AbortSignal.timeout,.
- 110Cluster and Process ManagersNode runs on one thread, so cluster or a process manager such as PM2 starts one worker per.
- 111Express MiddlewareMiddleware are functions that run in order: logging, parsing, authentication, then routes .
- 112TypeScript with NodeNode 22.6+ can run TypeScript files that only use erasable syntax with --experimental-stri.
Node.js in practicePremium7 lessons
- 113Project StructureGroup code by feature, keep configuration in one place, and separate routes from business .
- 114Handling Async ErrorsRejected promises with no catch can crash the process.
- 115Graceful ShutdownOn SIGTERM stop accepting connections, finish active requests, close databases, then exit.
- 116LoggingUse a structured logger such as pino that writes JSON lines, adds timestamps and levels, a.
- 117Security ChecklistValidate input, use helmet for headers, rate limit, keep dependencies updated with npm aud.
- 118Docker and DeploymentUse a small node image, copy package files first for layer caching, install only productio.
- 119Node.js Best PracticesPrefer async over blocking calls, handle every error, keep functions small, pin Node with .