title: "Spawn a thread"-like behaviour in node.js
body: <p>I want to add some admin utilities to a little Web app, such as "Backup Database". The user will click on a button and the HTTP response will return immediately, although the potentially long-running process has been started in the background.</p>
  
  <p>In Java this would probably be implemented by spawning an independent thread, in Scala by using an Actor. But what's an appropriate idiom in node.js? (code snippet appreciated)</p>
  
  <p>I'm now re-reading the docs, this really does seem a node 101 question but that's pretty much where I am on this...anyhow, to clarify this is the basic scenario :</p>
  
  <pre><code>function onRequest(request, response) {
      doSomething();
      response.writeHead(202, headers);
      response.end("doing something");
  }
  
  function doSomething(){
       // long-running operation
  }
  </code></pre>
  
  <p>I want the response to return immediately, leaving doSomething() running in the background.</p>
  
  <p>Ok, given the single-thread model of node that doesn't seem possible without spawning another OS-level ChildProcess. My misunderstanding. </p>
  
  <p>In my code what I need for backup is mostly I/O based, so node should handle that in a nice async fashion. What I think I'll do is shift the doSomething to after the response.end, see how that behaves.</p>