Runtime cheatsheet
Node.js 24 Cheatsheet
Everyday Node.js 24 and npm commands for running, testing and debugging projects.
Getting started
- Check the Node.js version — Print the installed Node.js version.
- Run a script — Run a JavaScript file with Node.js.
- Run a one-line expression — Evaluate a snippet and print the result without creating a file.
- Open the interactive shell — Start the REPL to try out expressions. Exit with .exit or Ctrl+D.
- Restart on file changes — Re-run the script automatically whenever it or its imports change.
- Load environment variables from a file — Read variables from a .env file into process.env before the script starts.
Packages with npm
- Create a package.json — Create a package.json with default values.
- Install all dependencies — Install everything listed in package.json.
- Add a dependency — Install a package and save it to dependencies.
- Add a development dependency — Install a package that is only needed while developing, such as a linter or test tool.
- Remove a dependency — Uninstall a package and remove it from package.json.
- Install exactly what the lockfile says — Delete node_modules and install from package-lock.json. Use it in CI.
- List top-level dependencies — Show the installed packages without their nested dependencies.
- Find outdated packages — Compare installed versions with the latest published versions.
- Update packages — Update dependencies within the version ranges set in package.json.
- Check for known vulnerabilities — Scan dependencies for published security advisories.
- Run a package without installing it — Run a package's command from the registry or from node_modules/.bin.
- Switch the project to ES modules — Set "type": "module" in package.json so .js files use import and export.
Scripts and testing
- Run a package.json script — Run a script from the scripts section of package.json.
- Run the start script — Run the start script, falling back to node server.js when none is defined.
- Run the test script — Run the test script from package.json.
- Run tests with the built-in runner — Find and run test files with the node:test runner, no extra dependencies.
- Run only matching tests — Run tests whose names match a pattern.
Debugging
- Start the debugger — Run with the inspector open, then attach from Chrome DevTools (chrome://inspect) or your editor.
- Pause on the first line — Start the inspector and wait at the first line until a debugger attaches.
- Show where warnings come from — Print a stack trace for process warnings such as deprecations.
- Raise the memory limit — Set the maximum size of the old generation heap in MiB.