Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8157887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:26:25+00:00 2026-06-06T17:26:25+00:00

I was trying to go through the tutorial nodetuts.com – tutorial 2 and unfortunatly

  • 0

I was trying to go through the tutorial nodetuts.com – tutorial 2 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):

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);

Anyway, determined to continue on I have been looking through the documentation on the node website and found this: http://nodejs.org/api/all.html#all_child_pid 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:

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);

Unfortunately when I refresh the page http://localhost:4000/ 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))

        res.writeHead(200);
            ^
TypeError: Object #<IncomingMessage> has no method 'writeHead'
    at Server.<anonymous> (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)

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. 🙁

  • I’m running windows 7
  • I have also looked at this code Why does response.write appear to block my browser in Node.js? and his code doesn’t work at all either.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:26:27+00:00Added an answer on June 6, 2026 at 5:26 pm

    You interchanged req and res in the function passed to createServer

    var http = require('http');
    
    var server = http.createServer(function(req, res){
        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);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working through this tutorial https://developers.google.com/cloud-print/docs/android for google cloud print. I am trying
After working through the Django tutorial I'm now trying to build a very simple
Hi guys I'm running through this tutorial: http://www.sencha.com/learn/a-sencha-touch-mvc-application-with-phonegap and trying to get the code
I am working through the tutorial for setting up Djapian and am trying to
I'm trying to go through the tutorial with luabind here, http://www.rasterbar.com/products/luabind/docs.html , however i'm
I am trying to get my head around NHibernate, I've run through this tutorial
I'm trying to get through the LiftWeb Getting Started Tutorial . This is what
I'm going through the rails by example tutorial series. I'm trying my best to
I've been trying to work through a tutorial which I foresee will be very
I was working through a tutorial at http://fszlin.blogspot.com/2010/05/comsuming-wcf-services-with-android.html and am having a problem. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.