title: How to restart node server on file change
body: <p>I'm developing a node/express app</p>
  
  <pre><code>$&gt; ./node_modules/babel/bin/babel-node.js index.js
  </code></pre>
  
  <p>Now I would like to reload the application if I make changes to <code>index.js</code> or any other dependency. How can I do this. I guess I have to use <code>gulp</code> for this, but than still I would like to have some advice on how to do this (which modules to use ect) </p>
  
  <p>UPDATE: I've just tested with <code>supervisor</code>, but when something changes I get the following error:</p>
  
  <pre><code>$&gt; /node_modules/.bin/supervisor --exec ./node_modules/babel/bin/babel-node.js index.js 
  
  crashing child
  Starting child process with './node_modules/babel/bin/babel-node.js     index.js'
  events.js:85
        throw er; // Unhandled 'error' event
              ^
  Error: listen EADDRINUSE
      at exports._errnoException (util.js:746:11)
      at Server._listen2 (net.js:1146:14)
      at listen (net.js:1172:10)
      at Server.listen (net.js:1257:5)
  </code></pre>
  
  <p>UPDATE: I just tried <code>nodemon</code> but I get the same errors as with <code>supervisor</code>:</p>
  
  <pre><code>$&gt; nodemon  --exec ./node_modules/babel/bin/babel-node.js index.js  --watch libs
  
  ...
  22 Aug 16:58:35 - [nodemon] restarting due to changes...
  22 Aug 16:58:35 - [nodemon] starting `./node_modules/babel/bin/babel-   node.js index.js`
  events.js:85
        throw er; // Unhandled 'error' event
              ^
  Error: listen EADDRINUSE
      at exports._errnoException (util.js:746:11)
      at Server._listen2 (net.js:1146:14)
      at listen (net.js:1172:10)
  </code></pre>
  
  <p>UPDATE: I've solved the <code>EADDRINUSE</code> issue by adding the following to <code>index.js</code></p>
  
  <pre><code>process.on('exit', () =&gt; {
      server.close();
  })
  
  process.on('uncaughtException', () =&gt; {
      server.close();
  
  })
  
  process.on('SIGTERM', () =&gt; {
      server.close();
  })
  </code></pre>
  
  <p>However, now it seems to restart, but the new code is not loaded</p>