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