nodemon is not restarting the server when using node-java package

☆樱花仙子☆ 提交于 2019-12-10 10:37:26

问题


When using node-java package, nodemon doesn't restart when the files change. If I remove node-java package then nodemon will restart when there are file changes.

Even the manual restart (rs) is not working when using node-java package in server. Following is the behavior.

alon

And even it throws the following:

events.js:85
     throw er; // Unhandled 'error' event
           ^
Error: listen EADDRINUSE
   at exports._errnoException (util.js:746:11)
   at Server._listen2 (net.js:1156:14)
   at listen (net.js:1182:10)
   at Server.listen (net.js:1267:5)

Since the port 4000 is being used only once in server and no where else, its behaving weird.


回答1:


It seems that node-java somehow magically 'overrides' what's happening when receiving SIGUSR2 signal. In such a case, the SIGUSR2 signal (used by nodemon) to restart the app may fail terminating the app.

(Quick) Fix:

after the node-java has screwed your SIGUSR2 handling mechanism, add the following snippet of code:

process.once('SIGUSR2', function() {
  process.kill(process.pid, 'SIGUSR2')
})

note that you must do this AFTER the node-java (or something which uses it, in my case it is node-tika) does its 'job' (in my case, immediately after requiring node-tika).

To be honest, I have only very little understanding, why this works and I'll be glad if someone can shed more light on this.



来源:https://stackoverflow.com/questions/32760782/nodemon-is-not-restarting-the-server-when-using-node-java-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!