/ npm

Installing dependencies with npm from git repositories

Recently we've been moving away from using Bower and just using npm to manage our project dependencies.

See: Why we should stop using Bower - and how to do it.

Most of the time it's pretty smooth as the majority of projects are available through npm as well as Bower, but what of the ones that just aren't?

Yesterday I wanted to try out Todd Motto's switch-messages.js with an AngularJS 1.2 project (yes; IE8) but it hasn't been submitted to npm and I didn't want to manually include the dependency or absorb the code directly into our build.

When I looked at the project I noticed that he'd referenced the git repo for installing through Bower:

bower install https://github.com/toddmotto/switch-messages.git

I tried the same through npm and (of course) it works.

npm install --save-dev https://github.com/toddmotto/switch-messages.git

This results in the following within our package.json:

"devDependencies": {
	"switch-messages.js": "git://github.com/toddmotto/switch-messages.git"
}

This is most likely something already known that we've just missed but I though I'd share for those who, like us haven't done this before.

This may not work with every git repo out there and most likely requires a valid package.json to be present but it's certainly something to try when a project is not already available via npm.

Paul Massey

Paul Massey

Founded the Genoveus Production Studio in 2003, JavaScript engineer at Scriptwerx, Director and DP at Mediawerx. Passionate about technology, filmmaking, robotics, IoT, photography, music and cars.

Read More