Consider Python right now:
django-admin.py
(a global command available in the environment) and create a django project.python manage.py
to run a command in your project.pundle
in your project to install packages that are project-specific and not environment-wide.With this, you can have a project with its packages, inside of an environment with certain wide-scoped packages providing their own command line to be executed. You have a single interpreter installed here, and *for the same interpreter you can install several different Django versions (you will need a different environment for each version, but on each one the python interpreter is aliased in).
Now i would like to think about nodejs and something like react, cordova, sails, meteor... you have many options to pick one, as long as they provide a command line.
npm install -g ionic
in a specific nvm-picked version.npm
has intrinsic support for my application.cordova build android
.But this brings me a problem: For the same node interpreter version I can have only one global cordova or ionic or whatever I want. This means: If I want to use a specific version of nodejs, and have two projects requiring different versions of the required command line, I cannot run a global command to create such projects. Example:
$ nvm use mynodeversion $ ionic start myApp
I will be using a specific version of ionic in that command, which will generate a that-version-specific boilerplate for my project. Assume the ionic version is x1.y1.z1.
Now I want to create a project with ionic version x2.y2.z2. But if I try to do this:
$ nvm use mynodeversion $ ionic start myApp
I will generate it for version x1.y1.z1 for the same interpreter, regardless which ionic version is referenced in my package.json.
In Python that is automatically solved with virtualenvs: you can have a specific Python interpreter, create many different environments with it, install different versions of your framework, one on each virtualenv, and generate different versions boilerplates for your projects, which will be compatible with the corresponding versions.
My question is: How can I do the same with nodejs? Provided, but not limiting to, the given example (another example could occur with sails or react-native).
That's simple: never use npm install -g
, use npm install --save-dev
. CLI utilities will be installed in node_modules/.bin
folder. For convenience it's also added to PATH for your npm scripts, so you can just call them without prefix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With