Repackaging node modules for local install with npm
If you need to install an npm package for nodejs from local files, because you can't or prefer not to download everything from the npmjs.org repo, or you don't even have a network connection, then you can't just get an npm package tarball and do `npm install <tarball>`, because it will immediately try to download all it's dependencies from the repo.
There are some existing tools and resources you can try:
- npmbox - https://github.com/arei/npmbox
- bundle.js gist - https://gist.github.com/jackgill/7687308
- relevant npm issue - https://github.com/npm/npm/issues/4210
I found all of these a bit over-wrought for my taste. So if you prefer a simple DIY approach, you can simply edit the module's package.json file, and copy all of its dependencies over to the "bundledDependencies" array, and then run npm pack to build a new tarball that includes all the dependencies bundled inside.
Using `forever` as an example:
- make a directory and run `npm init; npm install forever` inside of it
- cd into the node_modules/forever directory
- edit the package.json file
- look for the dependencies property
- add a bundledDependencies property that's an array
- copy the names of all the dependency modules into the bundledDependencies array
- save the package.json file
- now run `npm pack`. It will produce a forever-<version>.tgz file that has all it's dependencies bundled in.
- In online environment,
npm install --no-bin-link. You will have a entire flattened
- Then, bundle this flawless
tar / zip / rar / 7zetc
- In offline environment, extract the bundle, that's it