npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

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

install

npm i prepend-path

Downloadsweekly downloads

7

version

1.0.0

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability