Node.js RESTful API 在 Azure 上

Node.js RESTful API on Azure

我正尝试在 node.js 中迈出我的第一步,并且我一直在学习本教程: https://docs.microsoft.com/en-us/azure/app-service-api/app-service-api-nodejs-api-app 当我在 azure 中向云 shell 输入 npm install -g yo 时,出现此错误:

npm ERR! Linux 4.4.0-83-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "yo"
npm ERR! node v6.9.4
npm ERR! npm  v3.10.10
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access

npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!     at Error (native)
npm ERR!  { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!     at Error (native)
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/shiran_dror/app-service-api-node-contact-list/npm-debug.log

如何将 shell 用作 root/Administrator?

您的用户似乎没有在 /usr/local/lib/node_modules 中安装的权限。尝试删除 -g 选项以在本地安装。

npm install 命令前使用 sudo 以切换到 root 用户执行此命令(如果允许的话)。

您应该在本地机器上安装 Swaggerize,而不是在云端 Shell。

Install Swaggerize on your local machine. Swaggerize is a tool that generates Node.js code for your REST API from a Swagger definition.

完成本地开发后,使用 git 推送到应用服务(文档中的 "Deploy the API with Git" 部分)。

今天在 Cloud Shell 中,您被设置为 regular user without sudo permissions. As a result you cannot run sudo cmds from Cloud Shell currently. In the tutorial you are following, Cloud Shell helps for the sections that require az commands to create the Azure app service,因为 Azure CLI 2.0 在那里为您维护和更新。

section where you are npm installing Swaggerize 应该在您的本地计算机上,说明中包含此详细信息。