Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

nodemon the behavior when using node-java 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.

like image 369
Som Avatar asked Jan 08 '23 12:01

Som


1 Answers

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.

like image 95
Tomas Kulich Avatar answered Apr 30 '23 04:04

Tomas Kulich