在对其应用程序脚本进行更改后重新启动node.js服务器的最佳方法是什么

时间:2022-08-09 19:18:35

So, I'm in the process of learning node, and am finding that for testing, I have to kill the running instance of node, then start it up again with the new application code for the server. So, I first execute my node server like this: node myapp.js.

所以,我正在学习节点,我发现为了测试,我必须杀死正在运行的节点实例,然后使用服务器的新应用程序代码重新启动它。所以,我首先执行我的节点服务器:node myapp.js。

Then, I notice something isn't working right, or I want to add some new code to myapp.js. I go into Process Explorer (I'm running node on a Windows box), and kill the node.exe process, and then upload the new myapp.js file with the changes. Then I do node myapp.js to start it again to test again.

然后,我发现有些东西不正常,或者我想在myapp.js中添加一些新代码。我进入Process Explorer(我在Windows机器上运行节点),并终止node.exe进程,然后上传带有更改的新myapp.js文件。然后我做节点myapp.js再次启动它再次测试。

There has got to be an easier way to do this. I typed in node --help but there are too many flags listed to see if there is some kind of restart mechanism similar to apache on linux like: httpd -k restart. Is there a kind of "graceful" restart with node?

必须有一种更简单的方法来做到这一点。我键入了节点--help但是列出了太多的标志,看看是否有某种类似于Linux上的apache的重启机制,如:httpd -k restart。节点是否有一种“优雅”的重启?

2 个解决方案

#1


13  

Check out nodemon. Install it using npm install nodemon, after that simply use nodemon server.js if server.js is the file you're working on.

检查nodemon。使用npm install nodemon安装它,之后只需使用nodemon server.js,如果server.js是您正在处理的文件。

#2


1  

Use node-supervisor

使用node-supervisor

#1


13  

Check out nodemon. Install it using npm install nodemon, after that simply use nodemon server.js if server.js is the file you're working on.

检查nodemon。使用npm install nodemon安装它,之后只需使用nodemon server.js,如果server.js是您正在处理的文件。

#2


1  

Use node-supervisor

使用node-supervisor