Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a virtual environment for node.js?

People also ask

Do I need VPS for Node JS?

In some circumstances, it may be possible to use Node. js with shared hosting. This will largely be dependent on the hosting provider. Still, VPS hosting is a much better choice if you're looking to maximize your performance and security.

What is a node js environment?

Node. js is a runtime environment that allows software developers to work on the frontend and backend of web applications using JavaScript. It can be used in full-stack JavaScript development and features APIs to support HTTP requests, file systems and other server-side features.

Is node JS platform independent?

js is an open source software, and its installation on a server provides the Node program which itself enables JavaScript files to be executed on that server. Node. js is also cross-platform software, meaning that it is operating system independent such that it works on Linux, Windows and macOS.


nodeenv - virtual environment for node.js ( Analog virtualenv )


If having system wide npm packages is your main issue, then maybe consider using the very cool 'bundle' command with npm. This is closer to freezing gems or using bundler in rails, rather than rvm.

It's super easy. Just create a package.json file:

{ "name": "yourapp", "version": "0.0.1", "dependencies": {"jade": "0.4.1"}}

and then run:

npm bundle vendor

or if your npm version is >= 1.0 run:

npm install

to freeze into the vendor directory. and then use:

require.paths.unshift('./vendor');

There are also some Node version management systems that can help.

Check out Nave https://github.com/isaacs/nave

NVM could also be used https://github.com/creationix/nvm

There is also one called n https://github.com/visionmedia/n


bxjx's answer is conceptually accurate. However, please note that the bundle command no longer takes a directory. It always drops packages into the node_modules folder, so that npm knows where to find them later (and can avoid double-installing dependencies).

Any solution will probably involve installing npm and nave "system-wide" (that is, in your PATH, which could be in ~ somewhere), but then only installing your specific dependencies in the virtual environment.

I responded more thoroughly on the github issue.

tl;dr: The use case is valid and helpful, and while it's mostly there, it's not as well served as it could be. We should make sure to think it through and do it right.


You don't always need to install dependencies globally. Usually it's recommended because then you can use the commands an npm packages provides, but if you install it locally (in the node_modules) directory, you can also use these commands, they only wind up in the node_modules/.bin/ directory, so you'll have to type node_modules/.bin/<command>, which is annoying, but you can of course add this path to your PATH environment variable:

export PATH=node_modules/.bin:$PATH

Then you can just type <command> and it works!

There's actually an npm command that returns an absolute path to the .bin directory:

$ npm bin
/path/to/node_modules/.bin

This command also works when you're in a subdirectory of the project, it will return the first node_modules/.bin directory it finds in it's parent directories.

You can add this alias in your .bashrc to automatically add the .bin/ directory to your PATH:

alias nodebin='export PATH=$(npm bin):$PATH'

So when you're in a directory of a project that has a node_modules/ directory in the root, you can type nodebin and then you can use all the commands that are in the .bin/ directory!


looks there is a better way:

Installing Node.js and npm into a Python Virtualenv

now I can use node tools without mess the global bin environment


If you like it simple, I truely recommend visionmedia's n, could not be easier!

https://github.com/visionmedia/n