Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Friday Functions: npm Path

DZone's Guide to

Friday Functions: npm Path

Don't want to install npm modules globally all the time? Check out this solution from author James Carr.

· Web Dev Zone ·
Free Resource

Jumpstart your Angular applications with Indigo.Design, a unified platform for visual design, UX prototyping, code generation, and app development.

This 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!

Take a look at the Indigo.Design sample applications to learn more about how apps are created with design to code software.

Topics:
node.js ,npm ,function ,tip ,javascript ,zsh

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}