Installing "global" npm dependencies via package.json

uglymunky picture uglymunky · Feb 2, 2013 · Viewed 71.6k times · Source

I have a few "global" dependencies (jshint, csslint, buster, etc..) that I'd like to have automatically installed and executable via the command line when my package is installed via npm install. Is this possible?

Currently, I'm doing the following manually:

  1. npm install -g <package_name>
  2. from within my project: npm link <package_name>

Update: Just came across this feature request for npm. It seems like the scripts config within package.json is the way to go?

Update Again: Or, after reading the npm docs, maybe I'm supposed to use a .gyp file? I'm confused.

Answer

Jonathan Lonowski picture Jonathan Lonowski · Feb 2, 2013

It's not possible to specify dependencies as "global" from a package.json. And, this is by design as Isaac states in that feature request you referenced:

Yeah, we're never going to do this.

But, "binaries" can still be used when a package is installed locally. They'll be in .../node_modules/.bin/. And, you should be able to queue them up with a preinstall script.

Though, if the series of commands is rather lengthy (as "jshint, csslint, buster, etc.." would suggest), you may want to look into using a build tool such as grunt to perform the various tasks:

{
    // ...,

    "scripts": {
        "preinstall": "grunt"
    }
}