Nodejs Express应用程序部署到生产中 [英] nodejs express app deploying to production

查看:268
本文介绍了Nodejs Express应用程序部署到生产中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果这是一个基本问题,我仍在围绕Node.js部署工作.我有一个要在nodejs上编写的应用程序,我想将其部署到生产环境中.到目前为止,出于测试目的,我已经使用Express.但是据我所知,Express是开发服务器,而不是生产服务器.如何将nodejs应用程序部署到生产环境中,以及应该使用的服务器是什么.另外,我还有很多用于表达的代码,例如路由和中间件,当我部署到另一台服务器时,这如何工作?

Sorry if this is a basic question, I am still wrapping my head around nodejs deployments. I have an app written on nodejs which I want to deploy to production. So far for testing purposes I have used Express. However from what I know Express is a dev server and not a production server. How do I deploy the nodejs app to production and what is the server I should use. Plus I have a lot of code written for express like routes and middleware, how does this work when I deploy to another server?

推荐答案

使用express.js创建应用程序时,所有express模块​​都已在package.json中指定,并将作为npm模块安装.

When you create your application with express.js, all express modules have been specified in package.json and will be installed as npm modules.

您需要做的只是在生产服务器上安装node.js,将代码放在此处,运行npm install,然后使用NODE_ENV=production参数启动Web服务器.如果您可以使用grunt或gulp来处理静态资产(js/css缩小,...)以优化生产模式的性能,那将是一个加分.

All you need to do is just install node.js on your production servers, put your code there, run npm install, then start the web server with NODE_ENV=production param. It would be a plus if you can use grunt or gulp to process static assets (js / css minification, ...) to optimize the performance for production mode.

有关更多信息,您可以在这里看看: https://expressjs .com/en/advanced/best-practice-performance.html

For more information, you can take a look here: https://expressjs.com/en/advanced/best-practice-performance.html

这篇关于Nodejs Express应用程序部署到生产中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆