Early on in our journey into Ionic development we realized that using a single NodeJS instance would not do. Each project will start at different times, they will have different core versions of NodeJS, Ionic and Cordova, not to mention different plugins and different plugin versions. Each app really requires it's own instance of NodeJS.
For those who have developed in Python, there is a well known and much used solution i.e. the venv module.We thought we might use something similar for our NodeJS requirements.
We took the python script as a basic template and tweaked it for our purposes - activate_node.bash
For a new project we do the following -
- Download the .tar version of nodejs e.g. node-v8.9.1-darwin-x64.tar.gz
- Extract it to ~/opt/node-v8.9.1-darwin-x64
- Rename the folder for the new new project e.g. ~/opt/node-v8.9.1-darwin-x64.projectone
- Edit the "activate_node.bash" script to point to this new "projectone" nodejs environment
- Source the script to setup the environment
From then on you can install the nodejs packages, create the Ionic project and start developing. We keep the "activate_node.bash" script in the project directory.
To leave the nodejs virtual environment, simply run "deactivate" from the shell prompt.
Using this simple mechanism, you have a unique nodejs environment for each project.