Hello friends, if you're a Python developer like me, wandering through the world of JavaScript frameworks and npm packages, you may be scratching your head at why all the "Getting started" docs begin with installing the npm package globally!
What I mean is things like...npm install -g blah I almost gagged when I saw it for the first time, what if I want different versions of blah for different projects? Why is it system wide? Can't I just package things up all nicely and in an isolated fashion per project?
Yes, you can. I googled it for all of 30 seconds before deciding that it was too much effort and went out on a limb and googled "virtualenv for npm" and it exists!
So, before you say "Fuck this I'm going back to Django" hear me out.


Nodeenv is a Python package for Node.js virtual environments! You can sus it out on the pypi repo here


Installation is covered in the doc fairly well but I'll run over it anyway and attempt to humanise it a bit so you can see what's going on if you're unfamiliar with virtualenv.

Unless, god forbid, you're developing on a Windows machine, you should have python installed so you can run the following to install nodeenv;
pip install nodeenv
easy_install nodeenv

Getting started

To setup your nodeenv just create working directory (or pick and existing one, or do whatever, it doesn't matter) and run

nodeenv <name of environment>

To activate the virtual environment run

source <path to environment>/bin/activate

Now if you run which node or which npm you should see that it's pointing to your virtual environment.

You can install different node versions when you create the virtual environment by passing the --node argument

nodeenv <name of environment> --node x.x.x

You can see available node versions with

nodeenv --list


I used nodeenv to install Ghost on my server which runs this blog, so I'll show that as a real life example.

mkdir ghost-blog && cd ghost-blog

Ghost only supports certain versions on Node so I'll specify the version I want

nodeenv env --node 8.9.0

source env/bin/activate

npm install -g ghost-cli

Even though I specified the -g paramater it is still installed only to the nodeenv directory. Check out the image below where I deactivate the nodeenv and ghost is nowhere to be found globally!


So as you can see in the above image, in those first three lines, I have the virtualenv activated and so ghost is available to me, however, when I deactivate the virtualenv ghost can't be found, which is excellent... no system pollution!