简体   繁体   English

在生产中部署 Node.js 应用程序?

[英]Node.js application deployment in production?

I want to build/bundle and deploy the node.js, express in the production server such as Apache, Wamp or Tomcat.我想构建/捆绑和部署 node.js,在 Apache、Wamp 或 Tomcat 等生产服务器中表达。

My node.js application has pure back end logic such as API end point, DB connectivity etc.我的 node.js 应用程序具有纯后端逻辑,例如 API 端点、数据库连接等。

This will serve for the API request from out separate Front End application.这将为来自单独前端应用程序的 API 请求服务。 FE appln built and deployed independently in the server. FE 应用程序在服务器中独立构建和部署。 It works as expected.它按预期工作。

But didn't a idea for proper deployment of node.js backend application.但是没有正确部署 node.js 后端应用程序的想法。

Currently running the Node.js application as below当前运行 Node.js 应用程序如下

server.bat服务器.bat

rem node ./server.js
nodemon ./server.js PORT=7071

We will execute the server.bat file to start the server and it executes as expected.我们将执行 server.bat 文件以启动服务器并按预期执行。 But its getting terminated frequently.但它经常被终止。 So expectly a proper deployment something like build, build and deploy the code in the server.因此,期望适当的部署,例如在服务器中构建、构建和部署代码。

Do we need to any other task runners like Grunt/Babel for bundling?我们是否需要任何其他任务运行器(如 Grunt/Babel)进行捆绑?

You don't really need to bundle your code for running node.js applications on the server.你真的不需要捆绑你的代码来在服务器上运行 node.js 应用程序。 You can use Babel, but the only reason you would need to use it would be if you are using ECMAScript features that are not yet available in your version of the node.js runtime.您可以使用 Babel,但您需要使用它的唯一原因是您使用的 ECMAScript 功能在您的 node.js 运行时版本中尚不可用。

If you do decide to use Babel to enable features like import syntax, Babel will handle "transpiling" your code, which involves changing your code to rewrite the features that are not yet available in your node runtime to equivalent code that is compatible.如果您决定使用 Babel 来启用import语法等功能,Babel 将处理“转译”您的代码,这涉及更改您的代码以将节点运行时中尚不可用的功能重写为兼容的等效代码。 This is all optional, and more recent versions of node support most of the popular new JavaScript features.这都是可选的,更新版本的 node 支持大多数流行的新 JavaScript 功能。

What you are looking for is a process manager, something that will make sure the node process restarts if it stops running and basically help you manage the running server.您正在寻找的是一个进程管理器,它可以确保节点进程在停止运行时重新启动,并且基本上可以帮助您管理正在运行的服务器。 One popular option is PM2 ( http://pm2.keymetrics.io/ ).一种流行的选择是 PM2 ( http://pm2.keymetrics.io/ )。 PM2 also has additional features for monitoring metrics and assisting with deployment. PM2 还具有用于监控指标和协助部署的附加功能。

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

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