title: Node.js Beginner - Can't get past nodetuts tutorial number 2 - stdout and child process
body: <p>I was trying to go through the tutorial <a href="http://nodetuts.com/tutorials/2-webtail-nodejs-child-processes-and-http-chunked-encoding.html#video" rel="nofollow noreferrer">nodetuts.com - tutorial 2</a> and unfortunatly could not get the example working, I'm very new to node.js and going through any tutorials I can get hold of. I understand that node.js is still beta and I figured that the code that makes this work is now obsolete. (This is the code):</p>
  
  <pre><code>var http = require('http');
  var spawn  = require('child_process').spawn;
  
  http.createServer(function(request, response){
  
      response.writeHead(200, {
          'Content-Type' : 'text/plain'
      });
  
      var tail_child = spawn('tail', ['-f', 'test.txt']);
  
      tail_child.stdout.on('data', function(data){
          console.log(data.toString());
          response.write(data);
      });
  
  
  }).listen(4000);
  </code></pre>
  
  <p>Anyway, determined to continue on I have been looking through the documentation on the node website and found this: <a href="http://nodejs.org/api/all.html#all_child_pid" rel="nofollow noreferrer">http://nodejs.org/api/all.html#all_child_pid</a> This is not exactly what I want (I want to complete that tutorial linked to up top) but I wanted to get something todo with child process working and incorperated that code into this:</p>
  
  <pre><code>var http = require('http');
  
  var server = http.createServer(function(res, req){
      res.writeHead(200);
      res.end('testing');
  
  
      var spawn = require('child_process').spawn,
          grep  = spawn('grep', ['ssh']);
  
      console.log('Spawned child pid: ' + grep.pid);
      grep.stdin.end();
  
  }).listen(4000);
  </code></pre>
  
  <p>Unfortunately when I refresh the page <code>http://localhost:4000/</code> I get nothing and command prompt spits out: (I know it says writeHead is a problem, but it works fine in other examples - (like nodetuts - tutorial 1))</p>
  
  <pre><code>        res.writeHead(200);
              ^
  TypeError: Object #&lt;IncomingMessage&gt; has no method 'writeHead'
      at Server.&lt;anonymous&gt; (Z:\Joseph Goss Folder\Google Drive\Code\javascript_first\nodejs_first\stdoutTest.js:20:6)
      at Server.EventEmitter.emit (events.js:91:17)
      at HTTPParser.parser.onIncoming (http.js:1785:12)
      at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:111:23)
      at Socket.socket.ondata (http.js:1682:22)
      at TCP.onread (net.js:404:27)
  </code></pre>
  
  <p>I wonder why I can't get this working, I'm obviously missing something but I don't know what, and I can't even get past tutorial number 2. :(</p>
  
  <ul>
  <li>I'm running windows 7</li>
  <li>I have also looked at this code <a href="https://stackoverflow.com/questions/9012123/why-does-response-write-appear-to-block-my-browser-in-node-js?rq=1">Why does response.write appear to block my browser in Node.js?</a> and his code doesn't work at all either.</li>
  </ul>