26

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.

Katya S
  • 1,321
  • 3
  • 17
  • 31
  • There is a better way to do this now by using `npm pack `: https://stackoverflow.com/a/33549885/535827 – Brandon Dec 22 '18 at 00:10
  • My answer was deleted as duplicate in this thread, but I found that there is no easy way in 2019 to do this but I did get it to work. https://stackoverflow.com/a/58744517/101662 – Oliver Nov 07 '19 at 09:40

2 Answers2

38

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
aludvigsen
  • 5,893
  • 3
  • 26
  • 37
  • Hello... I'm still having problems - installing the packaged module globally doesn't seem to work :( Please see the updated question. Any thoughts? Thank you... – Katya S Apr 24 '14 at 11:54
  • I have also tried setting NODE_PATH in the env variables as suggested somewhere else... – Katya S Apr 24 '14 at 11:59
  • 1
    And cleared NPM cache. And checked the package: `npm test -g --verbose node-windows` and its all there... – Katya S Apr 24 '14 at 12:09
  • I tried this an npm hangs on the target machine at: npm install mytar.1.0.0.tgz fetchMetadata: sill resolveWithNewModule COR3Backend@1.0.0 checking installable status – Ya. Dec 14 '18 at 03:25
  • Does it work with packing from windows and installing on linux? – Raja Anbazhagan Nov 10 '21 at 07:37
  • I have to change the name of the project before npm install because it throws an error ```npm ERR! Refusing to install package with name "PROJECT" under a package npm ERR! also called "PROJECT". Did you name your project the same``` – wilcus Jun 01 '23 at 21:06
9

1 - In system with internet access install module with this command:

npm install [module name]

2 - go to %userprofile%\AppData\Roaming\npm\node_modules[module name]\ (e.g C:\Users\janson\AppData\Roaming\npm\node_modules\grunt-cli)
3 - run npm pack
4 - this should result in a [module name]-x.y.z.tgz file
5 - run npm i -g [module name]-x.y.z.tgz in offline system

ali khezri
  • 453
  • 1
  • 4
  • 18
  • 2
    You can run `npm pack ` to save the package as a tarball in one step. That is a bit simpler – Brandon Dec 22 '18 at 00:09
  • 1
    Running 5. still seems to want internet access npm ERR! network request to https://registry.npmjs.org/arrivals failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org – Oliver Nov 05 '19 at 15:07
  • @Oliver, I think it is because it needs to install the dependencies, and it can't connect to the internet, I am having the same problem – guergana Dec 10 '19 at 11:16
  • But sees you can get the complete tarball here: https://github.com/socketio/socket.io/releases – guergana Dec 10 '19 at 11:18