Friday Functions: npm Path
Don't want to install npm modules globally all the time? Check out this solution from author James Carr.
Join the DZone community and get the full member experience.
Join For FreeThis week’s Friday function is probably the most simplistic in my zsh library. Every time I worked with node.js I always got a little annoyed with having to reference the command line apps referenced under ./node_modules/bin
. Sure, I could do an npm install -g
but I don’t like mucking with my global environment on a per project basis. Python has virtualenvs which separate these concerns pretty well but to my knowledge node.js has no equivalent.
function npm_path(){
export PATH="$(npm bin):$PATH"
}
So my zshrc has contained this function for quite some time.
Now I just run npm path
from the root of a node.js project to quickly add its bin
directory to my path. I’m sure there are probably more elegant solutions these days… please let me know in the comments!
Published at DZone with permission of James Carr, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments