Skip to content

Instantly share code, notes, and snippets.

@emmanuelnk
Last active January 17, 2020 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emmanuelnk/bd75bfca23d98ed1b8863fcd60b86c71 to your computer and use it in GitHub Desktop.
Save emmanuelnk/bd75bfca23d98ed1b8863fcd60b86c71 to your computer and use it in GitHub Desktop.
Installing virtual node environments with nodeenv.
# start nodeenv virtual env if it exists
# for whenever you open integrated terminal in vscode
if [ -d ".nenv" ]; then
. ".nenv/bin/activate"
fi

summary of readme @ https://github.com/ekalinin/nodeenv

to install

sudo pip install nodeenv
nodeenv .nenv --node=8.9.3

to activate

. .nenv/bin/activate

to deactivate

deactivate_node

packages to be installed are kept in requirements.txt, like virtualenv

> cat ../prod-requirements.txt
connect@1.3.0
express@2.2.2

to install node.js from source

nodeenv --node=0.10.25 --source .nenv-0.10.25

If environment's directory already exists then you can use --force option

nodeenv --requirements=requirements.txt --jobs=4 --force nenv

create a new environement with the system-wide node

nodeenv --node=system

list locally installed packages

freeze -l ../prod-requirements.txt

create an environment from a requirements file

nodeenv --requirements=../prod-requirements.txt --jobs=4 .nenv

to add nodeenv to a project with python env (venv) first activate python .venv

. .venv/bin/activate

add a node virtual environment to this existing venv

nodeenv -p --node=x.x.x

if you already have an environment and want to update packages from requirements file you can use --update option:

. .nenv/bin/activate
nodeenv --requirements=requirements.txt --update .nenv

use ~/.nodeenvrc to set defaults

cat ~/.nodeenvrc
[nodeenv]
debug = False
jobs = 2
make = make
node = latest
npm = latest
prebuilt = False
profile = False
with_npm = False
without_ssl = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment