Review note (2026-10-21): The example versions were Node.js 12 and 14, both end-of-life since 2022 and 2023. They are now 22 and 24, the two LTS lines supported today. The workflow is unchanged. Check the Node.js release status before you copy version numbers, because the LTS lines move every year.
NVM selects a Node.js runtime, while NPX or npm exec runs a package command. They solve separate concerns and should be pinned according to the project policy.
Understanding NPX and NVM
Use a supported Node.js LTS pinned by the project. Prefer installed project scripts or npm exec --package=name -- command with an explicit reviewed version; allowing NPX to download an unpinned package adds a supply-chain and reproducibility risk.
NPX is a NPM tool that lets devs run Node packages without global installs. It’s handy for executing binaries from Node modules and running packages that leave no trace after execution.
NVM, on the other hand, is a version manager that lets you install multiple Node.js versions and switch between them effortlessly. It’s crucial for testing apps across Node versions or maintaining projects tied to specific Node versions.
Real-Life Scenario: Streamlined Project Setup
Imagine a backend dev juggling legacy Node.js versions and modern standards for a new microservice. Here’s how NPX and NVM can help:
Setting Up the Development Environment:
- The developer can use
nvmto switch between Node versions as needed. For instance, starting with Node 22, the older of the two supported LTS lines, for compatibility testing:1 2 3 4nvm ls-remote --lts | tail -n 5 nvm install 22 nvm use 22 node --versionnvm ls-remote --ltsis read-only and shows which LTS releases exist before you install one.node --versionconfirms the switch took effect. - They then use
npxto run a scaffolding tool likeexpress-generatorwithout installing it globally:1npx express-generator my-new-service
- The developer can use
Development and Testing:
- As development progresses, testing on newer Node versions is necessary. Here,
nvmallows easy switching:1 2nvm install 24 nvm use 24 - Using
npx, the developer can run local tests with tools likemochawithout permanent installations:1npx mocha
- As development progresses, testing on newer Node versions is necessary. Here,
CI/CD Integration:
- In a continuous integration setup, ensuring that the microservice builds and runs tests across all supported Node versions can be scripted with
nvm exec, which runs one command under a given Node version. The project’s ownnpm testscript runs the locally installed test tools, so nonpxdownload is needed:1 2nvm exec 22 npm test nvm exec 24 npm test
- In a continuous integration setup, ensuring that the microservice builds and runs tests across all supported Node versions can be scripted with
This isolates microservices from version conflicts and global deps, ensuring each is tested and deployed with the right Node env.
Using the tools together
The combination of NPX and NVM can significantly reduce setup times, avoid conflicts between differing Node module versions, and facilitate a cleaner development environment. Backend developers benefit from:
- Flexibility in managing multiple Node.js environments.
- Convenience of running any Node.js package executably without prior installation.
- Efficiency in testing across different environments with minimal configuration changes.