简体   繁体   English

在 Node.js 中无需重启服务器即可更新文件

[英]Update file without restart of server in Node.js

Is it possible to update a route,model or controller.js file without restarting the Node.js Server?.是否可以在不重新启动 Node.js 服务器的情况下更新路由、模型或 controller.js 文件?。

I'm currently dealing with a client who wants constant changes to the application in a very frequent event.我目前正在与一位希望在非常频繁的事件中不断更改应用程序的客户打交道。 And the application deals with user session etc.. Whenever we make any changes to the application it requires a restart for the update to get reflect, which is very expensive in-terms of an high traffic situation.应用程序处理用户会话等。每当我们对应用程序进行任何更改时,它都需要重新启动更新才能得到反映,这在高流量情况下非常昂贵。

I have seen some server application providing a feature called Rolling Restart but again I'm not sure whether it is a good way to maintain the user session across the restart event.我已经看到一些服务器应用程序提供了一个称为滚动重启的功能,但我再次不确定这是否是在重启事件中维护用户会话的好方法。 Or do we have any other solution to deal with this kind of situation.或者我们有没有其他解决方案来处理这种情况。

You can restart a server without downtime yes, I recommend you take a look at PM2 https://github.com/Unitech/pm2您可以在不停机的情况下重新启动服务器是的,我建议您查看 PM2 https://github.com/Unitech/pm2

You can have multiple instances of node running and when you set a restart it does it gradually, making that you don't have downtime, it also distributes load to the different instances running so it speeds up your app, hope this helps :-)您可以运行多个节点实例,当您设置重新启动时,它会逐渐重启,这样您就不会停机,它还会将负载分配给正在运行的不同实例,从而加快您的应用程序的速度,希望这会有所帮助:-)

Nodemon is what I have used before and I was very happy with it. Nodemon是我之前用过的,我对它非常满意。

Install安装

npm install -g nodemon

then run your app with然后运行你的应用程序

nodemon [your node app]

Done完毕

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

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