简体   繁体   English

如何在Microsoft Azure网站上安装npm作用域模块

[英]How to install a npm scoped module on Microsoft Azure Web Sites

My company has private scoped npm modules ie the ones starting with @mycompanyscope/mymodule . 我公司有私有范围的npm模块,即以@mycompanyscope/mymodule开头的模块。 By defaults all scoped modules in npm are private so you have to login first before publish 默认情况下,npm中所有作用域模块都是私有的,因此您必须先登录才能发布

npm login
Username:myusername
Password:**********
npm publish

The scoped module must have the property name with a scope in the package.json : 作用域模块必须在package.json具有属性name和作用域:

{
  "name": "@mycompanyscope/mymodule"
}

and the private key must be removed. 并且必须删除private

As soon as you login you get a token in the .npmrc file in your $HOME folder, that is like 登录后,您会在$HOME文件夹的.npmrc文件中获得一个token ,就像

//registry.npmjs.org/:_authToken=00000000-0000-0000-0000-000000000000
scope=mycompanyscope

At this point everything is properly setup to publish and install in this machine. 此时,所有内容都已正确设置为可以在此计算机上publishinstall If you grant access to other users, they can do npm login on their machines and get a token to work from there. 如果您授予其他用户访问权限,则他们可以在其计算机上进行npm login并从那里获取令牌以进行工作。

The problems come on the server side, depending on your server. 问题出在服务器端,具体取决于您的服务器。 On Heroku it should work as explained here . 在Heroku上,它应按此处说明的方式工作。

My server environment is Azure Web Sites. 我的服务器环境是Azure网站。 According to some docs, you should upload your .npmrc file to Azure during the deploying phase, and that would awesome, if I would have a way to get a token for that machine. 根据一些文档,您应该在部署阶段将.npmrc文件上传到Azure,如果我有办法获取该计算机的令牌,那将非常好。 If I try to login to Kudu PowerShell , the fact is that I just cannot login, the login process hangs at some point: 如果我尝试登录Kudu PowerShell ,事实是我无法登录,则登录过程会在某个时候挂起:

Kudu Remote Execution Console
Type 'exit' then hit 'enter' to get a new powershell process.
Type 'cls' to clear the console

PS D:\home> npm login
Username: mycompany
Password: *********
Email: (this IS public) npm@mycompany.com

so that I cannot generate any token from this machine. 因此我无法从这台机器生成任何令牌。 So how can I grant access here to let the npm install to run correctly for private scoped modules? 那么,如何在此处授予访问权限,以使npm install能够针对私有作用域模块正确运行?

[UPDATE] Thanks to the answer below I was able to deploy the npm scoped module (@ mycompanyscope/myModule) to Azure Web Sites, creating the .npmrc file in the project root folder (where the package.json is) and then writing there the token obtained after the npm login , and adding the registry to the npmjs.org registry: [更新]由于以下答案,我能够将npm范围内的模块(@ mycompanyscope / myModule)部署到Azure网站,在项目根文件夹( package.json所在的位置)中创建.npmrc文件,然后在此处写入在npm login之后获得的令牌,并将registry添加到npmjs.org注册表中:

//registry.npmjs.org/:_authToken=00000000-0000-0000-0000-000000000000
scope=mycompanyscope
@mycompanyscope:registry=https://registry.npmjs.org/

Have you tried to npm login your private npm registry on your local machine, to generate a .npmrc file in your node.js application, then deploy to Azure Web App with your application. 您是否尝试过npm login本地计算机上的私有npm注册表,以在node.js应用程序中生成.npmrc文件,然后将其与应用程序一起部署到Azure Web App。

Please refer to https://blog.maartenballiauw.be/post/2015/10/13/working-with-a-private-npm-registry-in-azure-web-apps.html for more details. 有关更多详细信息,请参阅https://blog.maartenballiauw.be/post/2015/10/13/working-with-a-private-npm-registry-in-azure-web-apps.html

Any update or further concern, please feel free to let me know. 如有任何更新或进一步的关注,请随时告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM