Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
672 views
in Technique[技术] by (71.8m points)

windows - How to install NodeJS project locally without internet connection?

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.

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.

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

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'

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

What do you think? And thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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. 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>.

Update

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

Try using the npm link command (docs on npm link):

  1. cd yourAppFolder
  2. npm link node-windows

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...