Learn JavaScript
❯ errors_modules.npm

npm: Packages & Scripts in JavaScript

$concept

npm (bundled with Node) manages dependencies and task running: npm init scaffolds package.json (name, version, scripts, dependencies), npm install <pkg> adds exact-versioned entries plus a lockfile for reproducible installs, and npm run <script> executes defined commands (dev, build, test). node_modules holds the hoisted dependency tree — never committed, rebuilt from the lockfile.

Scripts replace task runners for most projects (vite, jest, eslint invocations), npx runs binaries without installing, and semantic versioning ranges (^1.2.3) balance freshness with stability. Alternatives (yarn, pnpm) share the manifest concepts with different stores.

$how it works
1

init scaffolds

npm init -y writes package.json — identity, scripts, and dependency lists in one manifest.

2

install pins exactly

npm install lodash records ^4.17.21 plus lockfile exactness — teammates and CI install identically.

3

scripts run tasks

"scripts": {"dev": "vite", "test": "node --test"} — npm run dev/build/test standardizes workflows.

4

npx executes once

npx create-app runs packages without installing — scaffolders and one-off tools without footprint.

$example
$ npm init -y
$ npm install lodash
$ npm run test
Output
(package.json + node_modules created; test script executes)
1init scaffolds the manifest; install adds lodash pinned plus lockfile.
2node_modules materializes the dependency tree — rebuilt, never committed.
3The test script runs the project's defined check — workflow standardized.
$use cases
Adding libraries with version-pinned manifests plus lockfiles
Standardizing dev/build/test via npm scripts
One-off scaffolding with npx (no global installs)
Reproducible CI installs from lockfiles (npm ci)

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in JavaScript yourself — building beats watching.