Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm to install packages from local position rather than from web?

Tags:

node.js

npm

The problem drove me crazy, there is a package in npm database, but it has some bugs, which are already fixed in github, how could I make use of the fixed version(github version)?

like image 518
aaron Avatar asked Apr 24 '12 13:04

aaron


People also ask

Does npm install packages locally?

You can install a package locally if you want to depend on the package from your own module, using something like Node. js require . This is npm install 's default behavior.

Should I install NPM packages globally or locally?

It's best to install locally when relying on a package from your module, such as Node. js. This is how npm install works by default. The grunt CLI package, for example, must be installed globally before it can be used as a command-line tool.


1 Answers

Edit:

You can install directly from the GitHub repository, even just using the GitHub username and the repository name:

npm install LearnBoost/socket.io

You can also add a <commit-ish>, specifying e.g. a commit hash or a version tag, like so:

npm install LearnBoost/socket.io#1.7.x

Without a protocol, this will be interpreted as git://github.com/LearnBoost/socket.io. You can also prefix the repo with gitlab:, gist: or bitbucket:, respectively. For more information, see Using git URLs as dependencies.

You can install directly from a URL, example:

npm install https://github.com/LearnBoost/socket.io/tarball/master

You can find the URL on Github under "Downloads" on any project page. Select the "Download as tar.gz" link.

Or you can install a tarball:

npm install foo.tar.gz

See npm install(1).

Edit:

I should mention that this works equally well in package.json files. Specify the URL instead of the version in your dependencies, like so:

...
"dependencies": {
  "foo": "http://example.com/foo.tar.gz",
  "bar": "1.2.x",
  ...
}
like image 98
Linus Thiel Avatar answered Sep 22 '22 09:09

Linus Thiel