-4

When running npm run dev I'd like to have npm use a specific version of Node. In other words, I'd like to configure this script to use a specific Node path.

To make things even more complicated the npm run dev actually invokes Angular's ng CLI. So it's important this works too with the respective Node executable.

I tried setting NODE_PATH env var before ng serve, as well as looking for some conduit to put in .npmrc, but couldn't figure out a way to achieve what I am looking for.

3
  • Consider explaining your case in details. Notice that even if you use a different node executable to run a script, it's not guaranteed to be used if a script executes node processes internally Commented Mar 30 at 8:36
  • There's many details around what I want to achieve, but essentially it can be summed up as a self-contained project - i.e. a developer doesn't need to have pre-installed node, nvm, ng, what not ... Just downloads a project and does make start which in term will download npm and put it in .node subfolder of the project. Then, make uses the npm executable that was downloaded, to run all npm scripts. What I achieve, is a user should not worry about if they have npm installed locally and what version it is. I know nvm somehow "solves" this, but I don't like it too much.
    – LIvanov
    Commented Mar 30 at 8:41
  • It's faulty by design. You can patch node_modules/.bin/ to use specific node executable for package bins like "ng", or call them with their full paths like my-node ./node_modules/@angular/cli/bin/ng.js. This doesn't guarantee that the same "node" will be used through the process, but there's a chance it will work. nvm can affect "node" system-wide, that's its purpose, which this may be undesirable for a user. This is basically a case for containers Commented Mar 30 at 8:49

1 Answer 1

1

npm always uses the system-installed Node.js version.

If you want to install and use multiple versions, you need to use a version manager like nvm.

NODE_PATH isn't relevant in this situation, as it is used to maintain node_modules search paths.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.