4

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.

Som
  • 950
  • 2
  • 16
  • 29
  • I created example server using `node-java` module and server restarted successfully on file change. Did you create custom nodemon.json file containing configuration? – ezpn Sep 24 '15 at 19:18
  • @ezrepotein when using java.import this issue was observed. (as following) var java = require('java'); var preview = java.import('com.previewer.Previewer'); – Som Sep 28 '15 at 05:05
  • Similar issue found at nodemon repo, https://github.com/remy/nodemon/issues/573 there seems to no comments on it yet. – Som Sep 28 '15 at 05:22
  • After importing class I got the same issue. Maybe try supervisor as dannyn-mirth suggested on github issue. – ezpn Sep 28 '15 at 17:18

2 Answers2

7

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.

Tomas Kulich
  • 14,388
  • 4
  • 30
  • 35
  • A similar thing happens when sending a sigint (ctrl-c) to a ts-node application running via nodemon. To properly kill the application in that scenario, listen to the SIGINT signal, and then send the SIGKILL signal. – Laurens Rietveld Apr 13 '16 at 15:14
2

You can try running this command.

nodemon --signal SIGINT ./index.js

Alongkorn
  • 3,968
  • 1
  • 24
  • 41
adnls
  • 41
  • 1