Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using npm how can I download a package as a zip with all of 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.

So the scenario would be:

  1. Download package (to zip/tarball/whatever file) without installing it.

  2. Included in that downloaded file would be all of its dependencies (correct versions, and it's dependencies' dependencies).

  3. Transfer file to other computer.

  4. Run npm install to file location (optional -g important).

  5. Package is installed with dependencies.

  6. Happy camper.

I feel like there has to be a npm command to download and pack (create) files this way.

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

This is my first time using node so I'm affraid I'm not researching it correctly because lack of knowledge of the node/npm lingo.

like image 310
l__flex__l Avatar asked Apr 21 '15 09:04

l__flex__l


People also ask

How do I download NPM packages?

If you haven't installed npm, with the current public API, you can also access the information about a package in the npm registry from the URL https://registry.npmjs.org/<package-name>/ . Then you can navigate the JSON at versions > (version number) > dist > tarball to get the URL of the code archive and download it.

How do I save all dependencies to package json?

To add dependencies and devDependencies to a package. json file from the command line, you can install them in the root directory of your package using the --save-prod flag for dependencies (the default behavior of npm install ) or the --save-dev flag for devDependencies.

How do I download NPM packages globally?

NPM installs global packages into /<User>/local/lib/node_modules folder. Apply -g in the install command to install package globally.

How do I install multiple NPM packages in one command?

To install multiple packages, we need to use the npm install followed by the multiple package names separated by the spaces package1 package2 . This above command installs three packages, which are express, cors and body-parser. You can also checkout how to install the specific version of an npm package.

How do I install a package in NPM?

To install a public package, on the command line, run. npm install <package_name>. This will create the node_modules directory in your current directory (if one doesn’t exist yet) and will download the package to that directory.

What is npm and how to use it?

The registry (The npm registry is the database where all the packages exist, we can download packages published by other developers and can also publish our own packages to the registry) NPM can also be used to publish and manage private packages. A package is simply a program that performs one or more operations. How to Install npm?

How do I add dependencies to an app in NPM?

Make sure your app package has a package.json file at its root with all of your dependencies listed in it. You can make npm save your dependencies in package.json by doing npm install dependency-name --save. The --save flag will cause npm to write the dependency to your app's package.json file if it has one.

How to see which npm packages are outdated globally?

To see which NPM packages are outdated globally you can use this command: The command above also works for dev dependencies. To uninstall packages you simply use the uninstall command. Let’s uninstall lodash from our project


Video Answer


2 Answers

I just used this gist by Jack Gill to do exactly what you describe -- bundle up a package, with all its dependencies. Basically what the script does is re-write a module's package.json file to move all its dependencies to bundleDependencies, then pack the whole thing. Upload the resulting tarball to your server, then npm install it. Works a treat.

like image 159
endemic Avatar answered Oct 10 '22 16:10

endemic


  1. Download the package to a machine with internet.

  2. Make sure your app package has a package.json file at its root with all of your dependencies listed in it. You can make npm save your dependencies in package.json by doing npm install dependency-name --save. The --save flag will cause npm to write the dependency to your app's package.json file if it has one. If it doesn't have on then it will do nothing. You can also instruct npm to create a package.json file for your app if you need to by simply running npm init from in your app's directory.

  3. Run npm install from inside the app's directory. This will create the node_modules directory and install all the dependencies listed in the app's package.json file.

  4. Zip up the directory now that it has a node_modules directory in it with all your dependencies installed. Transfer the zip archive to another machine.

  5. Simply unpack the archive in its final destination and you're done. The app is now where it needs to be and the dependencies are already installed.

  6. Now just run the application with node app.js, replacing "app.js" with whatever the name of the app's main entry point file is.

like image 36
Chev Avatar answered Oct 10 '22 16:10

Chev