如何在没有互联网连接的情况下在本地安装NodeJS项目? [英] How to install NodeJS project locally without internet connection?

查看:667
本文介绍了如何在没有互联网连接的情况下在本地安装NodeJS项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,必须将其部署到无法连接到Internet的客户端Windows系统.我目前在D:\ NODE中有一个文件夹,其中包含node.exe和npm.cmd以及一个node_modules文件夹.为了能够从命令行运行节点,我在路径变量中添加了D:\ NODE.

I have a project which I will have to deploy to client Windows systems where it will not be possible to connect to internet. I currently have a folder in D:\NODE which contains node.exe and npm.cmd and a node_modules folder. To be able to run node from command line I have added D:\NODE to PATH variable.

我可以将大多数模块本地安装在我的项目的node_modules内部.但是,只有一个-节点窗口-需要全局安装才能正常工作.

I can have most of the modules installed locally inside node_modules of my project. However there's one - node-windows - which needs to be installed globally to work.

按照下面的建议,我去了节点窗口(全局安装)并将其打包(npm pack),这创建了一个tarball.然后,我已将该文件复制到我的项目中,并尝试将其像这样在全局安装到测试计算机上:npm install -g node-windows-0.1.5.tgz

Following suggestion below I went to node-windows (installed globally) and packaged it up (npm pack), which created a tarball. I have then copied that file with my project and tried to install it on the test machine globally like this: npm install -g node-windows-0.1.5.tgz

我可以看到它已安装在全局目录中.但是,当我尝试运行使用该模块的命令时,它抱怨找不到它:Error: Cannot find module 'node-windows'

I can see that it got installed in the global directory. However when I try to run the command which uses this module it complains that it cannot find it: Error: Cannot find module 'node-windows'

当我列出模块(npm list -g)时,它显然在列表中...

When I list the modules (npm list -g) it is clearly there in the list...

您怎么看?谢谢你.

推荐答案

您可以使用 npm 中的内置功能打包软件包,从而在没有互联网连接的系统上安装软件包.这样,节点模块将被正确安装.

You can install packages on a system without internet connection by packing them using built-in functionality in npm. This way, the node modules will be installed properly.

  1. 创建一个 package.json .
  2. 在您的 package.json 中,在bundledDependencies下列出所需的所有模块( npm上的文档).
  3. 运行npm install在打包之前安装节点文件.
  4. 使用npm pack创建一个压缩包.
  5. 在没有Internet连接的情况下将tarball复制到计算机上.
  6. 使用npm install <filename>安装模块.
  1. Create a package.json.
  2. In your package.json, list all the modules you need under bundledDependencies (docs on npm).
  3. Run npm install to install your node files before packing.
  4. Create a tarball with npm pack.
  5. Copy the tarball over to the machine without internet connection.
  6. Install the modules with npm install <filename>.

更新

关于您的评论,似乎找不到您全局安装的节点模块.

Regarding your comments, it looks like your globally installed node modules isn't found.

尝试使用npm link命令( npm链接上的文档):

  1. cd yourAppFolder
  2. npm link node-windows
  1. cd yourAppFolder
  2. npm link node-windows

这篇关于如何在没有互联网连接的情况下在本地安装NodeJS项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆