E
E
Evgeny Andreev2018-03-16 11:26:52
JavaScript
Evgeny Andreev, 2018-03-16 11:26:52

How to install packages in NodeJS when there is no internet?

Good afternoon. This question has already been asked, but there are no working answers. There is a computer without access to the Internet, you need the ability to install packages on it using npm.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
RidgeA, 2018-03-16
@RidgeA

No way.
If you need the code to work on a machine without the Internet - you need to create an "assembly" - a folder with your code and node_modules
To do this, I did this:
1 - I copied my code into a separate folder + package.json + package-lock.json + then, what is needed for the code to work (configs, etc.)
2 - npm i --prod is launched there (here it is necessary to distribute the dependencies correctly)
3 - the script is launched to clean the folder from unnecessary trash in the form of license files, etc. - so that there are fewer files ( https://www.npmjs.com/package/modclean)
4 - the folder is packed into an archive ( https://www.npmjs.com/package/bestzip)
5 - the temporary folder is cleaned
6 - next the archive can be uploaded to the desired machine, unpacked and run there

A
Abcdefgk, 2018-03-16
@Abcdefgk

Any package can be simply copied to the node_modules folder (transferred to a flash drive). But if it is complex (and 50-60 percent are complex), then you need to copy along with it all its dependencies and dependency dependencies (you can, of course, see them in the package.json files). So like this.
Once upon a time, about two years ago, Npm worked differently - it put the dependencies of each package inside the package, into the node_modules folder inside it. But at some point it was "corrected" - it began to dump all dependencies into the root node_modules. Transferring modules on a flash drive without the Internet has become more troublesome.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question