Advanced level · Module 2: Node.js for Tools and Servers · Lesson 1 of 4
The Node.js Runtime and npm
Understand what Node.js adds to JavaScript, use built-in modules and manage packages and versions with npm.
In this lesson you will
- Use Node.js built-in modules
- Install packages and understand semantic versions and lock files
Key concepts
built-in modules (node:fs, node:path)npm installsemantic versioningpackage-lock.json
The lesson
Node.js runs JavaScript outside the browser with access to files, processes and the network through built-in modules such as node:fs, node:path, node:http and node:crypto. There is no DOM.
npm install adds packages from the npm registry and records them in package.json. Versions follow semantic versioning: MAJOR.MINOR.PATCH, where a major change may break your code. package-lock.json records exact versions so every machine installs the same ones.
Every package you add is code you trust and maintain. Check its popularity, maintenance and size, and prefer built-in modules when they are enough.
Step by step
- Read a file with node:fs/promises.
- Build portable paths with node:path.
- Install one small package and inspect package.json and package-lock.json.
- Run npm audit and read the result.
Practice activity
Write a Node.js script that lists the files in a folder with their sizes, sorted from largest to smallest.
Expected result: The script prints a correct, sorted list using only built-in modules.
Check your understanding
-
What does package-lock.json record?
Show answer
The exact versions of every installed package.
-
In version 2.4.1, which number changes for breaking changes?
Show answer
The major version, 2.
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.