Javascript - Node.js¶
Managing Multiple Node Versions & Environments¶
-
NVM (node version manager):
- THIS IS THE ONE I (HAD) INSTALLED ON OS X
- https://github.com/creationix/nvm
-
NodeEnv
- https://pypi.python.org/pypi/nodeenv/
- http://ekalinin.github.io/nodeenv/
-
from StackOverflow:
Nvm works great if you just like to have various versions of node.js and npm installed at the same time. For the rest I found it enough to have required modules being installed to project directory with npm
Source Link -
from Quora:
I strongly recommend nave. It works well and arguably is more flexible than virtualenv. It works even better in combination with npm. Then, you can have nested shells each with their own set of modules.
The module system, npm, installs to your cwd (current working directory) so by switching folders you can have multiple environments per any individual Node.js version. You can also
npm install -g X
to install 'X' to your environment globally. Source Link
Setup on macOS¶
Note from http://nodejs.org
brew install node
// you don’t need to define a directory
// You can create a node project in any folder on your system,
// go there in a Terminal window and
// run your .js file with node filename.js, followed by hitting ENTER.
// then go to http://localhost:3000
// Using node-dev instead of node, automatically restarts
// your server, whenever it notices a file changed.
Setup I had done on MacBookAir (Note this is from circa 2014):
-
brew install nvm
# this is the node version manager
Note: Homebrew is officially unsupported -
Added the following line to
~/.bashrc
:
source $(brew --prefix nvm)/nvm.sh
Notes on usage:- https://github.com/nvm-sh/nvm
https://github.com/creationix/nvm
-
added the following line to
~/.bashrc
for tab completion in bash:
[[ -r $NVM_DIR/bash_completion ]] && . $NVM_DIR/bash_completion
-
installed node.js version 0.10:
nvm install 0.10
msg: "Now using node v0.10.26"
-
set node v0.10. as default:
nvm alias default 0.10
msg: "default -> 0.10 (-> v0.10.26)"
now any new terminal recognises the command "node" and runs node v0.10.**
NOTE:
After OS X upgrade to Mavericks nvm
is still installed (via homebrew).
But no version of node is installed and aliases were also cleaned out.