3 ### Get a PATH containing locally installed module executables.
5 `npm-path` will get you a PATH with all of the executables available to npm scripts, without booting up all of npm(1).
7 #### `npm-path` will set your PATH to include:
9 * All of the `node_modules/.bin` directories from the current directory, up through all of its parents. This allows you to invoke the executables for any installed modules. e.g. if `mocha` is installed a dependency of the current module, then `mocha` will be available on a `npm-path` generated `$PATH`.
10 * The directory containing the current `node` executable, so any scripts that invoke `node` will execute the same `node`.
11 * Current npm's `node-gyp` directory, so the `node-gyp` bundled with `npm` can be used.
18 # Prints the augmented PATH to the console
20 # /usr/local/lib/node_modules/npm/bin/node-gyp-bin:.../node_modules/.bin:/.../usr/local/bin:/usr/local/sbin: ... etc
23 Calling `npm-path` from the commandline is the equivalent of executing an npm script with the body `echo $PATH`, but without all of the overhead of booting or depending on `npm`.
27 This will set the augmented PATH for the current process environment, or an environment you supply.
30 var npmPath = require('npm-path')
31 var PATH = npmPath.PATH // get platform independent PATH key
33 npmPath(function(err, $PATH) {
35 // Note: current environment is modified!
36 console.log(process.env[PATH] == $PATH) // true
39 // /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/.../.bin:/usr/local/bin: ...etc
43 // more explicit alternative syntax
44 npmPath.set(function(err, $PATH) {
49 #### Synchronous Alternative
53 // supplying no callback will execute method synchronously
57 // more explicit alternative syntax
58 $PATH = npmPath.setSync()
65 env: process.env, // default.
66 cwd: process.cwd() // default.
69 npmPath(options, function(err, $PATH) {
73 npmPath.setSync(options)
82 This will get npm augmented PATH, but *does not modify the PATH in the environment*.
83 Takes the exact same options as `set`.
86 npmPath.get(function(err, $PATH) {
89 // Note: current environment is NOT modified!
90 console.log(process.env[PATH] == $PATH) // false
93 // options is optional, takes same options as `npmPath.set`
94 npmPath.get(options, function(err, $PATH) {
99 #### Synchronous Alternative
102 // supplying no callback will execute method synchronously
103 var $PATH = npmPath.get()
105 console.log(process.env[PATH] == $PATH) // false
107 // more explicit alternative syntax
108 $PATH = npmPath.getSync()
114 Both `set` and `get` take an optional options object, with optional `env` & `cwd` keys.
116 * Set `options.env` if you wish to use something other than `process.env` (the default)
117 * Set `options.cwd` if you wish to use something other than `process.cwd()` (the default)
119 There's also a `options.npm` property which you can set if you want `node-gyp` to be sourced from
120 an alternative `npm` installation.
122 ### Get the PATH environment variable key
125 // windows calls it's path "Path" usually, but this is not guaranteed.
126 npmPath.PATH // 'Path', probably
129 npmPath.PATH // 'PATH'
136 process.env[npmPath.PATH] // get path environment variable
138 // set path environment variable manually
139 process.env[npmPath.PATH] = npmPath.get()
141 // set path environment variable automatically
145 ### Get the PATH separator
149 npmPath.SEPARATOR // ';'
152 npmPath.SEPARATOR // ':'
157 Path lookup code adapted directly from npm.