Answers:
cd somedir
npm install .
要么
npm install path/to/somedir
somedir
必须包含其中的package.json
内容。
它也了解git:
npm install git://github.com/visionmedia/express.git
npm install
所有文件复制到您的项目目录之后。因此,require
语句中的路径将仅相对于您的项目目录。
install
就不会只是将其安装在该模块上,而不是将其安装在您要使用该模块的项目上吗?
#<ref>
在git url的末尾添加a 来指定分支/提交/标记,例如git://github.com/visionmedia/express.git#v0.0.1
; (b)为了安全起见,请添加"private": true
到您的私有存储库的package.json中。这将确保npm绝不会让您不小心将秘密信息发布到npm官方注册表。(根据debuggable.com/posts/…)–
npm i git+http://all/the/things.git
即使git clone http://all/the/things.git
工作正常也需要
在您的私人npm模块中添加
"private": true
到您的package.json
然后在另一个模块中引用私有模块,请在package.json中使用它
{
"name": "myapp",
"dependencies": {
"private-repo": "git+ssh://git@github.com:myaccount/myprivate.git#v1.0.0",
}
}
"private": true
部分不是必需的,但这将有助于防止您的私人回购被意外地发布到公共npm注册表。
我是否可以仅安装一个位于本地文件系统上的NPM软件包,甚至可以从git安装它?
是的你可以!从文档https://docs.npmjs.com/cli/install
一个包是:
- a)包含package.json文件描述的程序的文件夹
- b)包含(a)的压缩压缩包
- c)解析为(b)的网址
- d)
<name>@<version>
与(c)在注册表上发布的a- e)
<name>@<tag>
指向(d)的a- f)
<name>
具有满足“(e)”的“最新”标签的a- g)
<git remote url>
解析为(b)的a
npm不是很出色吗?
tar -czf my-package.tar.gz dist
(假设您的dist
文件夹中也包含正确的package.json
文件),则可以npm install ../my-lib/my-package.tar.gz
从其他项目中获取。
2016年1月更新
除了其他答案外,有时还需要在团队环境中使用私有模块。
无论Github上和到位桶支持生成一个团队的概念API密钥。此API密钥可用作此团队执行API请求的密码。
在您的私人npm模块中添加
"private": true
到您的package.json
然后在另一个模块中引用私有模块,请在package.json中使用它
{
"name": "myapp",
"dependencies": {
"private-repo":
"git+https://myteamname:aQqtcplwFzlumj0mIDdRGCbsAq5d6Xg4@bitbucket.org/myprivate.git",
}
}
其中团队名称= myteamname,API密钥= aQqtcplwFzlumj0mIDdRGCbsAq5d6Xg4
在这里,我引用了一个bitbucket存储库,但是使用github也几乎相同。
最后,作为替代方案,如果您真的不介意每月支付7美元(在撰写本文时),那么现在可以使用私有NPM模块了。
FWIW:在处理私有组织存储库时,我对所有这些答案都有疑问。
以下为我工作:
npm install -S "git+https://username@github.com/orgname/repositoryname.git"
例如:
npm install -S "git+https://blesh@github.com/netflix/private-repository.git"
我不太确定为什么其他答案在这种情况下不适合我,因为这是我在点击Google并找到答案之前首先尝试的方法。其他答案是我过去所做的。
希望这可以帮助其他人。
我遇到了同样的问题,经过一番搜索后,我发现了雷吉(https://github.com/mbrevoort/node-reggie)。看起来很扎实。它允许将NPM模块轻量发布到专用服务器。还不是很完美(安装时不进行身份验证),它还真的很年轻,但是我在本地进行了测试,它似乎按照其应有的方式工作。
那就是...(这只是他们的文档)
npm install -g reggie
reggie-server -d ~/.reggie
然后进入您的模块目录并...
reggie -u http://<host:port> publish
reggie -u http://127.0.0.1:8080 publish
最后,您可以通过直接在npm install命令中使用该url或在package.json中使用reggie来从reggie安装软件包。
npm install http://<host:port>/package/<name>/<version>
npm install http://<host:port>/package/foo/1.0.0
要么..
dependencies: {
"foo": "http://<host:port>/package/foo/1.0.0"
}
Npm现在提供无限的私人托管模块,每个用户每月只需$ 7,就像这样
cd private-project
npm login
在您的包json中设置 "name": " @username/private-project"
npm publish
然后要求您的项目:
cd ../new-project
npm install --save @username/private-project
从arcseldon的答案开始,我发现URL中需要团队名称,如下所示:
npm install --save "git+https://myteamname@aQqtcplwFzlumj0mIDdRGCbsAq5d6Xg4@bitbucket.org/myteamname/myprivate.git"
请注意,API密钥仅适用于团队,不适用于个人用户。
配置为从公共Github存储库安装,即使计算机位于防火墙下:
dependencies: {
"foo": "https://github.com/package/foo/tarball/master"
}
这就是我想要的:
# Get the latest from GitHub, public repo:
$ npm install username/my-new-project --save-dev
# Bitbucket, private repo:
$ npm install git+https://token:x-oauth-basic@github.com/username/my-new-project.git#master
$ npm install git+ssh://git@github.com/username/my-new-project.git#master
# … or from Bitbucket, public repo:
$ npm install git+ssh://git@bitbucket.org/username/my-new-project.git#master --save-dev
# Bitbucket, private repo:
$ npm install git+https://username:password@bitbucket.org/username/my-new-project.git#master
$ npm install git+ssh://git@bitbucket.org/username/my-new-project.git#master
# Or, if you published as npm package:
$ npm install my-new-project --save-dev
您可以使用Verdaccio为此,,它是Node.js中内置的轻量级私有npm代理注册表。它也是免费和开源的。通过使用Verdaccio,它不会像普通的私人npm注册表那样涉及那么多麻烦。
您可以在他们的网站上找到有关如何安装和运行它的详细信息,但步骤如下:
它要求node >=8.x
。
// Install it from npm globally
npm install -g verdaccio
// Simply run with the default configuration that will host the registry which you can reach at http://localhost:4873/
verdaccio
// Set the registry for your project and every package will be downloaded from your private registry
npm set registry http://localhost:4873/
// OR use the registry upon individual package install
npm install --registry http://localhost:4873
它还有一个泊坞窗,因此您可以轻松地将其发布到您的公共泊坞窗,瞧,您有一个私有的npm存储库,可以通过配置它的方式分发给其他人!