[Question] Best way to install modules to an offline pc

Hi,
to start, i'm using windows 10 :

The problem is: what is the best way to install a module such as node-red-contrib-s7 (for example) on a computer without internet connection?

On this offline device I have copied my Node-Red project but I am missing this node
(I have copied node-Red directly from a computer with connection to this offline one)

I think that copying a node directly is not the best way because there may be problems with versions or dependencies

How would you do it?

That topic came up here before.

See this thread for some ideas:

The problem is similar, yes, but not the same.

I already have NodeRed installed on my offline PC and I want to install a dependency like when you run (for example): npm install node-red-contrib-s7

I have tried to copy the npm cache of the online machine, copy it to the other and try to install it. Sometimes it works
I have tried to use "npm pack" with this method, but it does not seem the most appropriate, because in addition to not always working, it takes too much to copy the cache from one machine to another

Another option would be to reinstall everything, but I already have a service created

I think the solution is the same.
Just run npm install node-red-contrib-s7 in the NR workspace of your online machine, and copy the whole workspace to your offline machine (important is the node_modules dir).
By workspace I mean the directory where your flows.json resides. I don't recommend installing nodes globally.

In principle, this is how I do it all the time, as our customers' production machines have no internet connection.

No npm cache needed.
"npm pack" is for building an archive when developing packages.

In this case, would you overwrite the node_modules folder or skip those dependencies already installed? Couldn't there be a problem with the versions of each one?

on the other hand, this method seems simpler and more effective than what I was trying

I think it's basically copy node_modules and add the dependency manually to packages.json

or am I wrong?

In most cases I just replace the node_modules with the new one (rename or move it away first), so I always get a state that's consistent with the online machine. Plus, I have the option to quickly roll-back the old state by restoring the renamed node_modules directory if something goes wrong.

You don't need to update the package.json of your workspace, it isn't required by Node-RED or NodeJS to run. But I recommend keeping both workspaces (online and offline) in sync.

If you don't then npm will (almost) silently remove the package if you run npm, so suddenly you find that half your packages are missing.

@Nxito, in case you had not realised, I believe that @kuema maintains a full copy of the working system on his online system so that the whole thing can be copied across. The problem with trying to copy over just the new modules is that one module may bring other modules so you have to copy those also.

I meant the offline copy of the workspace... you don't run npm there anyway. As I said, I recommend keeping them in sync anyway. :slightly_smiling_face:

Indeed, that's the case. That online workspace is complete with package.json, flows.... etc. and checked into Git.

We've been using this workflow at work for some time now. We haven't come up with a better solution yet. But as I can see, we're not the only ones with that requirement. :sweat_smile:

It would be easy, I think, to forget which system you were on and try to use npm to install something. I don't know whether running something like npm list would remove them. I would not be surprised.

Well, if you keep the project files in sync the problem won't occur.

And in my case, I don't even have NPM on the offline machines available in the first place, so I never ran into that trap. :slightly_smiling_face:

I agree, use an online device - of the same platform type - to build a working environment and then synchronise it to the offline device - with a USB stick and RSYNC on both ends maybe if truly offline.

Removing npm from the offline device is a good idea. You should also remove npx as well.

In fact, I only keep the node.exe on our Windows-based production systems. Also easier to upgrade, because you can download the archive (no installer) from NodeJS and exchange the executable.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.