NodeJS模块安装 [英] NodeJS module installation
问题描述
我正在尝试在无法访问互联网的计算机上安装NodeJS服务器. 我复制了.exe并执行了它,但是现在我需要安装几个模块,所以我的问题是这样的:
I'm trying to install a NodeJS server on a computer without internet access. I copied the .exe and executed it but now I need to install a couple of modules, so my question is this:
我可以简单地从PC复制模块吗?还是我必须将服务器连接到互联网并使用npm?
Can I simply copy the modules from my PC? Or must I connect the server to the internet and use npm?
** 我已经将所有必需的模块安装到PC中,因此创建了以下package.json文件:
* EDIT : * I already had all the required modules into my PC, so I created the following package.json file:
{
"name": "MyNodeJS",
"version": "0.0.1",
"author": "aaa@aaa.aaa",
"description": "Modules required for MyNodeJS",
"main": "index.js",
"engines": {
"node": ">= 0.6.6"
},
"dependencies": {
"base64-js" : "0.0.2",
"bignumber" : "1.1.0",
"express" : "2.5.6",
"socket.io" : "0.8.7"
},
"bundledDependencies":["base64-js","bignumber","express","socket.io"]
}
然后执行"npm pack",创建具有以下结构的MyNodeJS-0.0.1.tgz文件:
and then executed "npm pack" witch created MyNodeJS-0.0.1.tgz file with the following structure:
MyNodeJS-0.0.1.tgz
|- MyNodeJS-0.0.1.tar
|- package
|- ALL MY NODEJS CONTENT
这正常吗?因为我期望只有模块.
Is this normal? Because I was expecting to have only the modules.
推荐答案
您可以创建自己的package.json.在bundledDependencies
下列出您需要的所有模块,然后通过npm pack
创建一个tarball.将压缩包复制到新计算机上,然后通过npm install <filename>
安装.而已. npm真的很性感. ;-)
You could create your own package.json. List all the modules you need under bundledDependencies
and create a tarball via npm pack
. Copy the tarball over to the new machine and install via npm install <filename>
. That's it. npm is really sexy. ;-)
这篇关于NodeJS模块安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!