npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

npm-path

v2.0.4

Published

Get a PATH with all executables available to npm scripts.

Downloads

3,178,521

Readme

npm-path

Get a PATH containing locally installed module executables.

npm-path will get you a PATH with all of the executables available to npm scripts, without booting up all of npm(1).

npm-path will set your PATH to include:

  • 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.
  • The directory containing the current node executable, so any scripts that invoke node will execute the same node.
  • Current npm's node-gyp directory, so the node-gyp bundled with npm can be used.

Usage

Command-line

# Prints the augmented PATH to the console
> npm-path
# /usr/local/lib/node_modules/npm/bin/node-gyp-bin:.../node_modules/.bin:/.../usr/local/bin:/usr/local/sbin: ... etc

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.

Set PATH

This will set the augmented PATH for the current process environment, or an environment you supply.

var npmPath = require('npm-path')
var PATH = npmPath.PATH // get platform independent PATH key

npmPath(function(err, $PATH) {
  
  // Note: current environment is modified!
  console.log(process.env[PATH] == $PATH) // true
  
  console.log($PATH)
  // /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/.../.bin:/usr/local/bin: ...etc
  
})

// more explicit alternative syntax
npmPath.set(function(err, $PATH) {
  // ...
})

Synchronous Alternative


//  supplying no callback will execute method synchronously
var $PATH = npmPath()
console.log($PATH)

// more explicit alternative syntax
$PATH = npmPath.setSync()

Optional Options

var options = {
  env: process.env, // default.
  cwd: process.cwd() // default.
}

npmPath(options, function(err, $PATH) {
  // ...
})

npmPath.setSync(options)

  // ...

Get PATH

This will get npm augmented PATH, but does not modify the PATH in the environment. Takes the exact same options as set.

npmPath.get(function(err, $PATH) {
  console.log($PATH)
  
  // Note: current environment is NOT modified!
  console.log(process.env[PATH] == $PATH) // false
})

// options is optional, takes same options as `npmPath.set`
npmPath.get(options, function(err, $PATH) {
  console.log($PATH)
})

Synchronous Alternative

//  supplying no callback will execute method synchronously
var $PATH = npmPath.get()
console.log($PATH)
console.log(process.env[PATH] == $PATH) // false

// more explicit alternative syntax
$PATH = npmPath.getSync()

Options

Both set and get take an optional options object, with optional env & cwd keys.

  • Set options.env if you wish to use something other than process.env (the default)
  • Set options.cwd if you wish to use something other than process.cwd() (the default)

There's also a options.npm property which you can set if you want node-gyp to be sourced from an alternative npm installation.

Get the PATH environment variable key

// windows calls it's path "Path" usually, but this is not guaranteed.
npmPath.PATH // 'Path', probably

// rest of the world
npmPath.PATH // 'PATH'

Example Usage

process.env[npmPath.PATH] // get path environment variable

// set path environment variable manually
process.env[npmPath.PATH] = npmPath.get()

// set path environment variable automatically
npmPath()

Get the PATH separator

// windows
npmPath.SEPARATOR // ';'

// rest of the world
npmPath.SEPARATOR // ':'

Credit

Path lookup code adapted directly from npm.

Thanks to Jordan Harband for his hard work adapting this to work on node 0.8.

License

MIT