Before unpacking npm itself, it helps to step back and ask what the node in npm gives us to work with. Node is JavaScript that runs outside the browser, doing work the in-browser variant cannot. That distinction matters because the code we write for websites already behaves much like Node's JavaScript—the difference lies in where it executes and thus what it can do. Understanding that foundation clarifies both the command line's role in the npm workflow and the purpose of the n in npm.
From script tags to dependency management
A package is code you didn't write but pulled from a public source and use in your project. jQuery, Bootstrap and Axios are familiar examples; Ruby calls the same idea "gems." Because your code depends on these files being present — jQuery's $ does nothing if jQuery isn't loaded — packages are also called dependencies, and package managers are sometimes called dependency managers. Packages range from a full framework to a single focused widget.
Traditionally you pulled a package in with a script tag pointing at an external URL (ideally a CDN):
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
Or you downloaded a copy into the project and linked it locally:
<script src="https://css-tricks.com/jquery.min.js"></script>
Where the script tag approach breaks down
This works — and you may never outgrow it — as long as your number of projects, collaborators and package updates stays manageable, and every package you use is client-side (browser) JavaScript or CSS. The last condition is the critical one, because plenty of tooling simply can't run in the browser alone.
Even in the simple case, the only way to see which packages you use and whether they're current is to open the HTML and read the script tags. That doesn't scale to hundreds or thousands of packages, and manual tracking invites human error. HTML shouldn't be the source of truth for a project's packages; mixing that concern into markup also creates conflicts when merging unrelated work between teammates.
A typical production app may rely on some or all of the following: Sass, PostCSS, Babel, TypeScript, hot module reloading via a dev server, bundling/minification/concatenation utilities, automatic image compression, testing libraries and linters. None of these appear in your script tags — and are accounted for nowhere in the project. Nothing records which tools are needed or what versions, so anyone (including your future self) would have to locate, download and install every one by hand, potentially a day-long job or worse.
What a package manager does
Dependencies are projects too, and they ship updates. Pasting a CDN script tag and calling it done doesn't make sure everything is installed and working on every collaborator's machine. A package manager makes a project's dependencies manageable: it knows what is installed, what has updates available, and whether one package conflicts with another — all from the command line with minimal effort. npm in particular adds further features beyond this core job.
Alternatives to npm
npm isn't the only JavaScript package manager. Yarn works much the same way, with deliberate interoperability, and the two have grown more similar over time; examples sometimes show yarn and npm side by side to signal that either is acceptable, not that both are needed together. Converting commands between them is generally trivial, and functionally the choice rarely matters — except that everyone on a project should use the same one for consistency. PnPm is effectively npm but more performant and efficient; the tradeoff is that it demands more technical know-how, making it an advanced option.
Why npm became the default
Ruby and PHP had solid package managers for years; JavaScript had none worth much before npm. The project began independently and open-source and was acquired by Microsoft in 2020. It has two parts: the package manager and the registry, a growing list of nearly two million installable packages. Think of it as an app store for front-end and Node projects — find a package, install it from the command line, update it when a new version ships, remove it when the project no longer needs it.
npx in brief
npx is part of npm, but invoking npx instead of npm runs a package's code without permanently installing it: it installs what it needs, runs it, and discards it. That suits installer scripts, and you could run npx sass with the necessary input and output arguments for a one-off compile — fewer installed packages to maintain.
npm installs and manages Node packages: tools that add features, developer conveniences, or both. Actually using it starts with installing it.



