DEV Community

loading...
Cover image for Setting up your Node environment using nvm for windows

Setting up your Node environment using nvm for windows

Dan Harris
combines pixel boxes and state machines 👩‍💻 frontend engineer 🥞, beer enthusiast 🍺
・3 min read

Never be off by a node version again 😲…. setup node version manager for Windows.

One of the great things about where I work is our commitment to giving juniors a go (for our sister social enterprise, Head Full of Heart, its actually the core mission 👍).
As most of our code repo's incorporate some kind of node build or run, a question that is commonly asked is how to setup your environment to actually run node.

Well... have no fear 😱, that's where this short article comes in.

* Just a reminder, this article shows the setup in windows... but setup in Mac or Linux is pretty similar 👍.


🤷‍♀️ why bother managing node versions?

Well I'm glad you asked! When working on a project (especially within a team), its ideal to have as similar an environment as possible to both your peers, but more importantly, your build server.
Strange issues 👻 can arise when using mismatched versions of node (and by extension npm)... e.g. dependencies failing to build, hard to debug runtime errors .etc.

So... when you're working across a single project at any time, that's fairly easy. You simply install a matching version of node & off you go. The trick comes when you need to jump across multiple projects (which may have multiple node requirements).

By managing our node version, we're able to quickly switch our global node context. Hazah! Problems gone 🦸‍♀️.


⏳ install nvm-for-windows

To manage our node version and flip between various node versions, we're going to use an awesome tool called nvm-for-windows.

Installing nvm-for-windows is as simple as heading on over to
github.com/coreybutler/nvm-windows/releases and downloading the latest release 👉 nvm-setup.zip. The setup zip bundle will include an installer... and away you go.

A couple of recommendations when running through the installer;

  • install nvm-for-windows into a directory other than the default (e.g. c:\my-workspace\apps\nvm). This will fix a couple of strange issues that sometimes occur with spaces in the directory path (Program Files\nvm). It also allows you to segregate your global node installs and any other node_modules.
  • after installing, sometimes you may have to restart your computer for the path variables to be picked up (e.g. if you get the error 'nvm' is not recognized as an internal or external command)

After installing, you should be able to use the nvm command on the commandline. Next up, let's set a node version to use.


⚡ use a node version

Setting our node version is now as simple as installing the right version using nvm 👉 nvm install 8.9. We then need to 'use' that version (which is how we change node versions using nvm - unless you've got a slicker setup using a .nvmrc or similar)... 👉 nvm use 8.9.

* I'd run the above commands - or at least the install command - using an elevated commandline, sometime odd things happen 🤷‍♂️.


🤔 well that wasn't hard?

Hopefully the above was pretty easy... but sometimes odd things occur. Let me know in the comments if you get a strange error or some other heeby-jeeby.


* As always - constructive feedback, opinions, improvements and comments are all welcome. Comment here, or hit me up on twitter @danharris_io  . Thanks for reading!
* original (unedited) title icon courtesy of Freepik from flaticon.

Discussion (0)

Forem Open with the Forem app