0

I'm trying to add ping results (isAlive) to the stream below so that later I can pipe to http response but I received the following error

events.js:85
throw er; // Unhandled 'error' event

I don't understand what it means and would be grateful for any help afforded to me?

var Readable = require('stream').Readable;
var s = new Readable;
var ping = require('ping');

var hosts = ['192.168.1.1', 'google.com', 'yahoo.com'];
hosts.forEach(function(host){
    ping.sys.probe(host, function(isAlive){
        var msg = isAlive ? 'host ' + host + ' is alive' : 'host ' + host + ' is dead';
        //console.log(msg);
        s.push(msg)
    });
});
//s.push(null) ;
//s.pipe(process.stdout);
1
  • Which version of node are you using? Commented Sep 28, 2015 at 15:22

1 Answer 1

1

I modified your code:

var Readable = require('stream').Readable;
var s = new Readable();
var ping = require('ping');

s.on('error', function(err){
  console.error(err)
})

var hosts = ['192.168.1.1', 'google.com', 'yahoo.com'];
hosts.forEach(function(host){
    ping.sys.probe(host, function(isAlive){
        var msg = isAlive ? 'host ' + host + ' is alive' : 'host ' + host + ' is dead';
        //console.log(msg);
        s.push(msg);
    })
});

You were missing the () on var s = new Readable()

By adding the error listener to your reader, you'll see that the tool you're using is throwing the following error: Error: not implemented

Sorry, I thought I had sent this earlier. Fortunately stack saves unsubmitted posts.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.