Node.js fundamentals: JavaScript on the server
You use JavaScript outside the browser with Node.js: reading files, writing command-line tools, managing npm packages and building a small HTTP server.
Level 201 · 19 lessons · 15 practice labs
Lessons
The runtime
- What Node.js is: JavaScript outside the browser
- The REPL, scripts and the process object
- Modules: ESM and CommonJS
- The file system: fs/promises
- The path and os modules
- Short task: a tool that sorts files by extension
Packages and tools
- npm init and installing packages
- package.json and npm scripts
- Version ranges and the lockfile
- Command-line arguments: parseArgs
- Environment variables and configuration
- Short task: a CLI tool that builds a report from CSV
Network and events
- EventEmitter and event-driven code
- Streams: processing a large file in pieces
- A server with the http module
- Serving static files and a JSON endpoint
- Calling another service with fetch in Node
- Error handling and exiting the process cleanly
- Capstone: a notes service
Practice labs
- List a folder's files by size: Read a folder's files with fs/promises and print them with their sizes from largest to smallest.
- Move old log files to an archive: Write a script that moves .log files older than seven days into an archive folder named by date.
- Find identical files by hash: Find files in a photo folder with different names but identical content using hashes, and report them.
- Add a package and run a script: Install a date-formatting package in a new project and define a script that runs with "npm run report".
- Fix a project broken by a version range: Fix a project that breaks because two machines installed different package versions, by examining the lockfile and version range.
- Prune unused dependencies: Find dependencies in package.json that the code never uses, remove them and verify the project still works.
- Read command-line flags: Write a small tool that reads --count and --quiet flags with parseArgs and applies defaults.
- Move settings into environment variables: Move a hard-coded port and database path into environment variables and give a clear error when one is missing.
- Merge settings in priority order: Write a config layer that merges defaults, a config file, environment variables and flags in the right priority.
- Trigger order notices with events: Trigger the email and stock modules with EventEmitter events when an order arrives.
- Count 404s in a large log with streams: Read an access log too big for memory line by line and count the 404 responses.
- Compress a file while copying with streams: Copy a large export file through gzip with pipeline and clean up the partial file if it fails.
- Set up a mini server that returns JSON: Write a server with the http module that returns the server time as JSON for /time.
- Call a rate service and convert prices: Write an endpoint that fetches rates from the lab's currency service and returns the price list in the requested currency.
- Shut the server down cleanly: Write a server that refuses new requests on SIGTERM, finishes running ones and exits with the right code.
About this course
You use JavaScript outside the browser with Node.js: reading files, writing command-line tools, managing npm packages and building a small HTTP server.
What you will learn
- The runtime
- Packages and tools
- Network and events
Prerequisites
Finishing the level 101 courses of the same path, or knowing those topics, is enough.
Lab environment
Lessons run in your own Kali Linux terminal that opens in the browser. Nothing to install; the lab starts clean in every lesson.
Frequently asked questions
- Is this course right for my level?
- The course is at level 201; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.