title: Using grunt to run a node server and do cleanup after
body: <p>So basically this is what I want to do. Have a grunt script that compiles my coffee files to JS. Then run the node server and then, either after the server closes or while it's still running, delete the JS files that were the result of the compilation and only keep the .coffee ones.</p>
  
  <p>I'm having a couple of issues getting it to work. Most importantly, the way I'm currently doing it is this:</p>
  
  <pre><code>grunt.loadNpmTasks("grunt-contrib-coffee");
  grunt.registerTask("node", "Starting node server", function () {
      var done = this.async();
      console.log("test");
      var sp = grunt.util.spawn({
          cmd: "node",
          args: ["index"]
      }, function (err, res, code) {
          console.log(err, res, code);
          done();
      });
  });
  
  grunt.registerTask("default", ["coffee", "node"]);
  </code></pre>
  
  <p>The problem here is that the node serer isn't run in the same process as grunt. This matters because I can't just CTRL-C once to terminate JUST the node server.</p>
  
  <p>Ideally, I'd like to have it run in the same process and have the grunt script pause while it's waiting for me to CTRL-C the server. Then, after it's finished, I want grunt to remove the said files.</p>
  
  <p>How can I achieve this?</p>
  
  <p>Edit: Note that the snippet doesn't have the actual removal implemented since I can't get this to work.</p>