Saturday, March 16, 2024

Setting the Default Node.js Model with NVM

Must read


Introduction

Node.js is a strong JavaScript runtime that builders use to construct scalable purposes. Nevertheless, with new variations being launched continuously, managing these variations could be troublesome. That is the place Node Model Supervisor (NVM) is available in. NVM is a command-line software that permits you to set up, replace, and change between totally different Node.js variations simply.

Personally, I work on lots of totally different initiatives, every of which have been both began at totally different instances or require totally different Node options, so having the ability to change between Node variations simply is essential.

On this Byte, we’ll give attention to learn how to handle the default Node.js model with NVM.

Setting Default Node.js Model with NVM

Setting a default Node.js model with NVM is a simple course of. First, you’ll want to be certain that NVM is put in in your system. If it isn’t, you may obtain and set up it from the official NVM GitHub repository.

As soon as NVM is put in, you may set up a selected Node.js model through the use of the nvm set up command adopted by the model quantity. For instance, to put in Node.js model 14.15.1, you’ll run:

$ nvm set up 14.15.1

You can even be extra generic and simply specify 14, for instance, which might then set up the most recent model with the foremost model of 14.

After the set up, you may set this model because the default utilizing the nvm alias default command:

$ nvm alias default 14.15.1

Now, each new terminal session will use Node.js model 14.15.1 by default.

Switching to Newest Node.js Model as Default with NVM

If you wish to use the most recent out there model of Node.js as your default, you are able to do so simply with NVM. First, you’ll want to discover out the most recent model. You are able to do this with the nvm ls-remote command, which lists all of the Node.js variations out there for obtain:

$ nvm ls-remote

As soon as you have recognized the most recent model, you may set up it and set it because the default, identical to we did within the earlier part:

$ nvm set up <latest-version>
$ nvm alias default <latest-version>

Substitute <latest-version> with the precise model quantity.

Switching to LTS Node.js Model as Default with NVM

Lengthy-Time period Help (LTS) variations of Node.js are variations which might be supported and maintained by the Node.js group for an extended interval. These variations are typically extra steady and advisable for manufacturing environments.

To change to the most recent LTS model, you should use the nvm set up --lts command, which can set up the most recent LTS model:

$ nvm set up --lts

After which set it because the default:

$ nvm alias default --lts

Observe: The --lts flag will also be used with the nvm alias default command to set the most recent LTS model because the default.

This fashion, you may be certain that your improvement surroundings is all the time utilizing a steady, long-term supported model of Node.js.

Checking Node.js Model in VS Code

In VS Code, you may simply test the model of Node.js that is at present in use. To do that, you may must open the terminal inside VS Code. If you happen to’re undecided learn how to open the terminal, you are able to do it by clicking on View within the menu, after which deciding on Terminal.

As soon as the terminal is open, you may test the Node.js model by coming into the next command:

$ node -v

This command prompts Node.js to return the model quantity. The output ought to look one thing like this:

v14.15.1

The v stands for model, and the numbers following it characterize the model of Node.js that’s at present lively. On this case, the model is 14.15.1.

Observe: Keep in mind, the model of Node.js that VS Code makes use of is set by the system PATH, or by the node model set by NVM in the event you’re utilizing it. If you happen to’ve put in a number of variations of Node.js, you may change between them utilizing NVM.

If for some motive you are still seeing an older model when working the above instructions, strive restarting VS Code.

Conclusion

Managing totally different variations of Node.js generally is a bit difficult, particularly if you’re engaged on a number of initiatives that every require a unique model. Nevertheless, with the Node Model Supervisor (NVM), you may simply change between totally different variations of Node.js as wanted. Not solely does this make it simpler to handle your initiatives, but additionally helps just be sure you’re all the time utilizing the proper model of Node.js.



Supply hyperlink

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article