I've searched the wiki modules page, but I can't find anything similar to virtualenv (python) or rvm.
我已经搜索了wiki模块页面,但是我找不到任何与virtualenv (python)或rvm类似的东西。
Anyone here separates node.js in their own env? I really don't like to install npm system-wide.
这里的人分离节点。在他们自己的环境中?我真的不喜欢在系统范围内安装npm。
8 个解决方案
#1
33
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.
如果您的主要问题是系统范围的npm包,那么可以考虑使用npm非常酷的“bundle”命令。这更接近于冻结宝石或在rails中使用bundler,而不是rvm。
It's super easy. Just create a package.json file:
超级简单。只是创建一个包。json文件:
{ "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版本是>= 1.0运行:
npm install
to freeze into the vendor directory. and then use:
冻结到供应商目录。然后使用:
require.paths.unshift('./vendor');
#3
18
There are also some Node version management systems that can help.
还有一些节点版本管理系统可以提供帮助。
Check out Nave https://github.com/isaacs/nave
检查车轮的https://github.com/isaacs/nave
NVM could also be used https://github.com/creationix/nvm
NVM也可以使用https://github.com/creationix/nvm
There is also one called n https://github.com/visionmedia/n
还有一个叫n https://github.com/visionmedia/n。
#4
7
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).
bxjx的答案在概念上是准确的。但是,请注意,bundle命令不再占用目录。它总是将包放入node_modules文件夹,这样npm就知道以后在哪里找到它们(并且可以避免重复安装依赖项)。
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.
任何解决方案都可能涉及到安装npm和nave“系统范围”(也就是说,在您的路径中,它可能位于~某处),但是只在虚拟环境中安装特定的依赖项。
I responded more thoroughly on the github issue.
我对github的问题做出了更彻底的回应。
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.
这个用例是有效的和有用的,虽然它大部分都在那里,但它并没有得到应有的服务。我们应该确保仔细考虑,并把它做好。
#5
1
looks there is a better way:
看来还有更好的办法:
Installing Node.js and npm into a Python Virtualenv
安装节点。js和npm成为Python的Virtualenv。
now I can use node tools without mess the global bin environment
现在,我可以使用节点工具而不会破坏全局bin环境
#6
1
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:
您并不总是需要全局地安装依赖项。通常推荐使用npm包提供的命令,但是如果您在本地(node_modules)目录中安装它,您也可以使用这些命令,它们只在node_modules/中结束。bin/ directory,因此必须输入node_modules/。bin/
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目录的绝对路径:
$ 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.
当您处于项目的子目录中时,这个命令也可以工作,它将返回第一个node_modules/。它在它的父目录中找到它。
You can add this alias in your .bashrc
to automatically add the .bin/
directory to your PATH
:
您可以在.bashrc中添加此别名,以自动将.bin/目录添加到路径:
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!
因此,当您在根目录中有node_modules/目录的项目目录中时,您可以输入nodebin,然后您可以使用.bin/目录中的所有命令!
#7
0
If you like it simple, I truely recommend visionmedia's n, could not be easier!
如果你喜欢它简单,我真诚地推荐visionmedia的n,这是再简单不过了!
https://github.com/visionmedia/n
https://github.com/visionmedia/n
#8
-1
I think it doesn't make sense at all to work on node environment without an installed node. It's like you didn't install python and pip when you want to work on a python project! of course for using virtualenv and virtualenvwrapper the pre-require is python.
If you want to work on a Node project it's really normal to install node and npm at least.
If you just want to run a python project on the web (for example with Django), you can use the build version of the javascript file and load this file into your project.
我认为在没有安装节点的节点环境下工作是没有意义的。就像当您想在python项目上工作时,您没有安装python和pip一样!当然,对于使用virtualenv和virtualenvwrapper时,预先要求的是python。如果您希望在节点项目上工作,那么至少安装Node和npm是正常的。如果您只想在web上运行一个python项目(例如Django),您可以使用javascript文件的构建版本并将该文件加载到项目中。
#1
33
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.
如果您的主要问题是系统范围的npm包,那么可以考虑使用npm非常酷的“bundle”命令。这更接近于冻结宝石或在rails中使用bundler,而不是rvm。
It's super easy. Just create a package.json file:
超级简单。只是创建一个包。json文件:
{ "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版本是>= 1.0运行:
npm install
to freeze into the vendor directory. and then use:
冻结到供应商目录。然后使用:
require.paths.unshift('./vendor');
#2
#3
18
There are also some Node version management systems that can help.
还有一些节点版本管理系统可以提供帮助。
Check out Nave https://github.com/isaacs/nave
检查车轮的https://github.com/isaacs/nave
NVM could also be used https://github.com/creationix/nvm
NVM也可以使用https://github.com/creationix/nvm
There is also one called n https://github.com/visionmedia/n
还有一个叫n https://github.com/visionmedia/n。
#4
7
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).
bxjx的答案在概念上是准确的。但是,请注意,bundle命令不再占用目录。它总是将包放入node_modules文件夹,这样npm就知道以后在哪里找到它们(并且可以避免重复安装依赖项)。
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.
任何解决方案都可能涉及到安装npm和nave“系统范围”(也就是说,在您的路径中,它可能位于~某处),但是只在虚拟环境中安装特定的依赖项。
I responded more thoroughly on the github issue.
我对github的问题做出了更彻底的回应。
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.
这个用例是有效的和有用的,虽然它大部分都在那里,但它并没有得到应有的服务。我们应该确保仔细考虑,并把它做好。
#5
1
looks there is a better way:
看来还有更好的办法:
Installing Node.js and npm into a Python Virtualenv
安装节点。js和npm成为Python的Virtualenv。
now I can use node tools without mess the global bin environment
现在,我可以使用节点工具而不会破坏全局bin环境
#6
1
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:
您并不总是需要全局地安装依赖项。通常推荐使用npm包提供的命令,但是如果您在本地(node_modules)目录中安装它,您也可以使用这些命令,它们只在node_modules/中结束。bin/ directory,因此必须输入node_modules/。bin/
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目录的绝对路径:
$ 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.
当您处于项目的子目录中时,这个命令也可以工作,它将返回第一个node_modules/。它在它的父目录中找到它。
You can add this alias in your .bashrc
to automatically add the .bin/
directory to your PATH
:
您可以在.bashrc中添加此别名,以自动将.bin/目录添加到路径:
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!
因此,当您在根目录中有node_modules/目录的项目目录中时,您可以输入nodebin,然后您可以使用.bin/目录中的所有命令!
#7
0
If you like it simple, I truely recommend visionmedia's n, could not be easier!
如果你喜欢它简单,我真诚地推荐visionmedia的n,这是再简单不过了!
https://github.com/visionmedia/n
https://github.com/visionmedia/n
#8
-1
I think it doesn't make sense at all to work on node environment without an installed node. It's like you didn't install python and pip when you want to work on a python project! of course for using virtualenv and virtualenvwrapper the pre-require is python.
If you want to work on a Node project it's really normal to install node and npm at least.
If you just want to run a python project on the web (for example with Django), you can use the build version of the javascript file and load this file into your project.
我认为在没有安装节点的节点环境下工作是没有意义的。就像当您想在python项目上工作时,您没有安装python和pip一样!当然,对于使用virtualenv和virtualenvwrapper时,预先要求的是python。如果您希望在节点项目上工作,那么至少安装Node和npm是正常的。如果您只想在web上运行一个python项目(例如Django),您可以使用javascript文件的构建版本并将该文件加载到项目中。