简体   繁体   English

将Node.js应用程序部署到Azure的最佳实践

[英]Best practice for nodejs app deployment to Azure

Recently I started to work on Nodejs project, and we are using Azure Functions for this. 最近,我开始从事Nodejs项目的工作,为此我们正在使用Azure Functions。 I'm curios about app deployment to Azure. 我对将应用程序部署到Azure感到好奇。

First I tried to find a serverless plugin to install dependency packages during deployment process. 首先,我试图找到一个无服务器插件来在部署过程中安装依赖项包。 Couldn't find an easy way to do this. 找不到简单的方法可以做到这一点。

After some googling and reading this documentation I figured out that best practice is to install packages on build step, and deploy already generated node_modules. 经过一番查阅和阅读本文档后,我发现最佳实践是在构建步骤上安装软件包,并部署已经生成的node_modules。

Deploying the node_modules directory as part of your application increases the size of the deployment. 将node_modules目录部署为应用程序的一部分会增加部署的大小。 ... however, it does guarantee that the versions of the modules used in production are the same as the modules used in development. ...但是,它确实确保生产中使用的模块版本与开发中使用的模块版本相同。

So I tried to follow this, and deploy small app with dependencies: 因此,我尝试遵循此方法,并部署具有依赖项的小型应用程序:

"dependencies": {
  "azure-function-express": "^1.3.0",
  "body-parser": "^1.18.2",
  "express": "^4.16.2",
  "cookie-parser": "^1.4.3",
  "cors": "^2.8.4"
}

Zip file to deploy was about 709 KB. 要部署的Zip文件约为709 KB。 It deployed successfully. 它部署成功。 But when I added one more package (mongoose) 但是当我再添加一个包(猫鼬)时

"dependencies": {
  "azure-function-express": "^1.3.0",
  "body-parser": "^1.18.2",
  "express": "^4.16.2",
  "cookie-parser": "^1.4.3",
  "cors": "^2.8.4",
  "mongoose": "^5.0.11"
}

The size of zip became 2.83 mb and deployment hangs with message "Uploading function: ...", function not deployed, and no logs. zip的大小变为2.83 mb,部署挂起并显示消息“ Uploading function:...”,功能未部署,并且没有日志。

It hangs... I'm not sure what the precise reason is, but it doesn't work even with few packages, what if I add more big packages? 它挂起了...我不确定确切的原因是什么,但是即使只有很少的程序包也不起作用,如果我添加更多的大程序包怎么办?

I kindly ask your advice how you solve such kind of issues, and which method best works for you to build and deploy Nodejs Azure Functions. 请问您如何解决此类问题以及哪种方法最适合您构建和部署Nodejs Azure Functions。 Thank you! 谢谢!

Solution is to use webpack to bundle a lot of packages into one file. 解决方案是使用webpack将许多软件包捆绑到一个文件中。 And then it's easy and fast to deploy. 然后可以轻松,快速地进行部署。 If you use serverless framework there is a package serverless-webpack to do the job. 如果使用serverless框架,则有一个无服务器Webpack包可以完成此工作。

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

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