prepend-path

1.0.0 • Public • Published

prepend-path

npm version Build Status Build status Coverage Status

Prepend a path to the existing PATH environment variable cross-platform way

const prependPath = require('prepend-path');
 
process.env.PATH; //=> '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin'
 
prependPath('additional/bin');
 
process.env.PATH; //=> 'additional/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin'

Installation

Use npm.

npm install prepend-path

API

const prependPath = require('prepend-path');

prependPath(path)

path: string (a path to prepend)
Return: string (modified PATH environment variable)

It prepends the given path to the process.env.PATH, or its equivalent on Windows for example process.env.Path, along with the platform-specific path delimiter.

prependPath('foo/bar');
// POSIX
//=> 'foo/bar:/usr/local/bin:/usr/bin:/bin:...'
 
// Windows
//=> 'foo\\bar;C:\\Users\\appveyor\\AppData\\Roaming\\npm;C:\\...'

Prepending a new path to the PATH is, in other words, making it precedent to the every existing one while searching executable files.

const {existsSync} = require('fs');
const which = require('which');
 
existsSync('/User/example/new_path/npm/bin/npm'); //=> true
 
which.sync('npm'); //=> '/usr/local/bin/npm'
prependPath('/User/example/new_path/npm/bin');
which.sync('npm'); //=> '/User/example/new_path/npm/bin/npm'

License

ISC License © 2017 Shinnosuke Watanabe

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    4
    • latest

Version History

Package Sidebar

Install

npm i prepend-path

Weekly Downloads

4

Version

1.0.0

License

ISC

Last publish

Collaborators

  • shinnn