Using npm how to download a package as zip with all its dependencies included in the package

What I'm trying to do is download packages with all their dependencies in order to transfer them to another computer that does not have an Internet connection, and install it there.

Thus, the script will look like this:

  • Download the package (in zip / tarball / any file) without installing it.

  • This downloaded file will include all its dependencies (correct versions and dependency dependencies).

  • Transfer the file to another computer.

  • Run npm install at the file location (optionally -g is important).

  • The package is installed with dependencies.

  • Happy tourist.

I feel that there must be an npm command to download and package files in this way.

I tried looking for a solution to this to no avail.

This is my first time using node, so I'm afraid that I am not studying it correctly, because there is a lack of knowledge about node / npm lingo.

+8
npm package
source share
3 answers

I just used this gist from Jack Gill to do exactly what you described - to build a package with all its dependencies. Basically, what the script does is overwrite the package.json module to move all its dependencies to bundleDependencies , and then pack it all. Download the resulting tarball to your server, then npm install it. It works with pleasure.

+1
source share

Just run npm install in the package directory and save it. Assuming there are no non-npm requirements that you need for meat, and both machines are running the same version of node, nothing else needs to be done. All downloaded dependencies will be installed inside ./node_modules . But in general, it would be nice to archive the entire package, as the developer could implement some additional configuration procedures.

+1
source share
  • Download the package to a computer with the Internet.

  • Make sure your application package has the package.json file in its root with all the dependencies listed in it. You can do npm to save the dependencies in package.json by running npm install dependency-name --save . The --save flag --save force npm to write the dependency to the package.json application file, if any. If this does not happen, he will not do anything. You can also tell npm to create a package.json file for your application if you just need to run npm init from the application directory.

  • Run npm install from the application directory. This will create the node_modules directory and install all the dependencies listed in the package.json application.

  • Replace the directory now that it has a node_modules directory in which all your dependencies are installed. Transfer the zip archive to another computer.

  • Just unzip the archive to your final destination, and you're done. The application is now where it should be, and the dependencies are already installed.

  • Now just launch the application with node app.js , replacing "app.js" with any name of the main file of the application entry point.

+1
source share

All Articles