Node.js 24 cheatsheet

Node.js 24: Packages with npm

12 common Node.js 24 tasks.

Create a package.json

Create a package.json with default values.

npm init -y

Install all dependencies

Install everything listed in package.json.

npm install

Add a dependency

Install a package and save it to dependencies.

npm install express

Add a development dependency

Install a package that is only needed while developing, such as a linter or test tool.

npm install --save-dev typescript

Remove a dependency

Uninstall a package and remove it from package.json.

npm uninstall express

Install exactly what the lockfile says

Delete node_modules and install from package-lock.json. Use it in CI.

npm ci

Caution: Removes the existing node_modules folder, and fails if package.json and the lockfile disagree.

List top-level dependencies

Show the installed packages without their nested dependencies.

npm ls --depth=0

Find outdated packages

Compare installed versions with the latest published versions.

npm outdated

Update packages

Update dependencies within the version ranges set in package.json.

npm update

Check for known vulnerabilities

Scan dependencies for published security advisories.

npm audit

Run a package without installing it

Run a package's command from the registry or from node_modules/.bin.

npx prettier --write .

Switch the project to ES modules

Set "type": "module" in package.json so .js files use import and export.

npm pkg set type=module

Was this page helpful?