Why I can't create a TCP client?

var net = require('net'),
 clientSocket = new net.Socket();


clientSocket.connect('8080', 'localhost', function(){

clientSocket.on('data', function(data) {
 console.log('data:' + data);

clientSocket.on('close', function() {

Empirically revealed that the error in the call to the connect () method. But where exactly, I can not understand
July 8th 19 at 16:39
2 answers
July 8th 19 at 16:41
There covece functions have an argument responsible for description errors. Use it to understand why.

Just make sure that the server is raised on that port on that host that need. Well, what he raised. Easiest via netcat.
Tried. This is issued

Error: connect ECONNREFUSED
at errnoException (net.js:901:11)
at Object.afterConnect [as oncomplete] (net.js:892:19) - brannon_Christians commented on July 8th 19 at 16:44
: so while the server is up? Because it seems that you're either not there or connecting XS. - Allene_Crona78 commented on July 8th 19 at 16:47
July 8th 19 at 16:43
If you connect, then either the IP address, try '' or port, but rather the first one, you can try on some other language to do the same thing, it will help to "localize" the problem.
Tried. Not working. Replaced input parameters will be {port: '8080', host:''}, function(){}). Also not working - brannon_Christians commented on July 8th 19 at 16:46
: so on this port someone is listening? - Allene_Crona78 commented on July 8th 19 at 16:49

Find more questions by tags Node.jsJavaScript