Node.js – events js 72 throw er unhandled ‘error’ event

I’m new to Node.js and wish to run a program using streams. With other programs, I had to start a server simultaneously (mongodb, redis, etc) but I have no idea if I’m supposed to run one with this. Please let me know where I am going wrong and how I can rectify this. Thanks in advance.

This is the program:

var http = require('http'),
feed = '';

function decide(cb) {
setTimeout(function () {
if ( { return console.log('rejected'); }        
}, 2000);

http.get(feed, function (res) {

decide(res.pipe.bind(res, process.stdout));

//using anonymous function instead of bind:
// decide(function () {
//   res.pipe(process.stdout)
// });


This is the cmd output:

<b>C:5-Employing Streams5-Employing Streams\23-Playing with pipes>node npm_stre

throw er; // Unhandled 'error' event
Error: Parse Error
at Socket.socketOnData (http.js:1583:20)
at TCP.onread (net.js:527:27)
share|improve this question
Are you sure the URL is right? I get nothing from there, but I do get something from (without the underscore). Also see here for an example of how to catch errors from http.get. –  user3374348 Apr 9 at 12:35

2 Answers

Close nodejs app running in another shell. Restart the terminal and run the program again.

Another server might be also using the same port that you have used for nodejs. Kill the process that is using nodejs port and run the app.

To find the PID of the application that is using port:8000

$ fuser 8000/tcp
8000/tcp:            16708

Here PID is 16708 Now kill the process using the kill [PID] command

$ kill 16708
share|improve this answer

Well, your script throws an error and you just need to catch it (and/or prevent it from happening). I had the same error, for me it was an already used port (EADDRINUSE).

share|improve this answer
Please provide code for this answer… –  Adam Aug 27 at 6:05
There is no code to provide. –  lama12345 Aug 28 at 0:06

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s