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 8163269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:58:50+00:00 2026-06-06T18:58:50+00:00

This is a node tutorial for a beginner. Why doesn’t my code work? It’s

  • 0

This is a node tutorial for a beginner. Why doesn’t my code work? It’s identical to his and I have tried workarounds without success. Please help if you can.

http://nodetuts.com/tutorials/2-webtail-nodejs-child-processes-and-http-chunked-encoding.html#video

In this tutorial, he writes a log/text file to the webpage located at localhost:4000, previous examples work (tutorial 1) however I can’t get this to do anything at all, it runs and that’s all.

Could anyone get this printing a file to the webpage please. 🙂
Thanks!

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', '/var/log/system.log']);

    request.connection.on('end', function(){
        tail_child.kill();
    });

    tail_child.stdout.on('data', function(data){
        console.log(data.toString());
        response.write(data);
    });

}).listen(4000);

I have tried the following and they are making no difference:

    console.log(data.toString());
    response.write(data);
    response.end();

and

    console.log(data.toString());
    response.end(data);

Edit after MiguelSanchezGonzalez answer:

I added tail_child.stderr.pipe(process.stdout); into the right place, and this is the response I am getting:

CreateProcessW: The system cannot find the file specified.

A file certainly does exist here, and I have also tested many different paths including text files in the same folder as the script (such as '/test.txt' for example. So maybe i’m wrong, i just assumed when it said file it was talking about my file.


Edit 2:
I also checked if the path exists (crudely built from here): Fastest way to check for existence of a file in NodeJs and it does say that the file indeed exists.

This code:

var file = path.normalize = ('var/log/system.log');

    fs.exists(file, function(exists){
        util.debug(exists ? "yep, its there":"nope");
    });

    console.log(file);

outputs this:

var/log/system.log
DEBUG: yep, its there
  • 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-06T18:58:53+00:00Added an answer on June 6, 2026 at 6:58 pm

    Hy Joseph, I recomend to you to change this line in your code to see what kind of error do you have

    http.createServer(function(request, response){
    
        response.writeHead(200, {
            'Content-Type' : 'text/plain'
        });
    
        var tail_child = spawn('tail', ['-f', '/var/log/system.log']);
    
        request.connection.on('end', function(){
            tail_child.kill();
        });
    
        tail_child.stdout.on('data', function(data){
            console.log(data.toString());
            response.write(data);
        });
    
        /* Add this line to see the error in your terminal */
        tail_child.stderr.pipe(process.stdout);
    
    }).listen(4000);
    

    This will show you the description of the error, maybe you don’t have this file in your filesystem o you can’t open it, try changing the path file to other that you know that exists and can open it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how can I avoid this in jQuery: $(this).parents(.node-inner).children().children().children(); I tried: $(this).parents(.node-inner).children(.className); but it doesn't
So I've been following this tutorial http://drupal.org/node/751826 . I took the following code: <?php
I have encountered with this nice tutorial to node.js . There is some example
I have a data object that looks like this: { 'node-16': { 'tags': ['cuda'],
I have this kind of node in my xml document: <parent ...> <a .../>
I have this TreeView: Main Node Header=Main Sub Node Header=Sub1 Final Node Header=Item1 Final
I have a content type called fund. The contents of this is in node-fund.tpl.php
this is a b-day reminder code utilizing linkedlists typedef struct node { char name[61];
I have seen this in some book/ tutorial. When you pass in the head
I am playing around with node.js and based on this wonderful tutorial I created

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.