32

I want to use NodeJS and AngularJS for a small project.

Can I use conda's virtualenv to install these packages inside a separate virtual environment, and then have them removed from the system once I delete the virtualenv?

dreftymac
  • 31,404
  • 26
  • 119
  • 182
Fakher Mokadem
  • 1,059
  • 1
  • 8
  • 22
  • You might want to look into Node version managers for that. [nvs](https://github.com/jasongin/nvs/blob/master/doc/SETUP.md) can be installed into a custom location (such as your virtualenv or project directory) – fardjad Jul 27 '18 at 11:42
  • Thx, so, installing Node inside a conda virtualenv is the same as installing it on the system? It wont be removed if I delete the virtual env? – Fakher Mokadem Jul 27 '18 at 11:47
  • I haven't tried it TBH, but nvs gets installed in home directory by default. So deleting the virtualenv shouldn't affect it. – fardjad Jul 27 '18 at 11:50
  • Okay, thx for the help – Fakher Mokadem Jul 27 '18 at 11:52

1 Answers1

60

You can for sure use conda to create virtual environments for nodejs programs.

$ conda create -yn myapp nodejs
$ conda activate myapp
$ node --version
v8.11.3
$ npm --version
5.6.0

And then in the environment myapp, you can do all of your app development and once you are done, removal is also easy:

$ conda env remove -yn myapp

Instead of environments, you can also use prefixes. Like:

$ conda create -yp ./myapp nodejs
$ conda activate ./myapp
$ node --version
v8.11.3
$ npm --version
5.6.0

And once you are done, just delete it.

$ conda env remove -yp ./myapp

OR

$ rm -fr ./myapp
Nehal J Wani
  • 16,071
  • 3
  • 64
  • 89
  • 18
    Spread the word! Conda is *not* tied to python, except the fact that it was written in python. – Nehal J Wani Aug 02 '18 at 03:44
  • 2
    @FakherMokadem: Please accept the answer as it solved your problem :) – Cleb Sep 28 '18 at 10:02
  • 1
    I did, sorry for missing that. – Fakher Mokadem Sep 28 '18 at 11:27
  • 1
    Then if I run `npm install -g X` in the conda env, will the global package X be in the conda env too? Are there related docs on "behavior of other package managers in conda env"? – kakakali Jun 22 '21 at 16:33
  • 1
    `npm install -g X` will install `X` in `/path/to/conda-environment-for-nodejs/lib/node_modules/X` – Nehal J Wani Jun 22 '21 at 17:11
  • @NehalJWani I can't get this to work. For some reason in my environment the system node is default and npm install -g X installs to system module path. https://stackoverflow.com/questions/69020379/nodejs-anaconda-and-setting-nodepath – Codey McCodeface Sep 03 '21 at 20:54