title: port error in node.js Error: connect ECONNREFUSED
body: <p>I am trying to run an application on a local host but constantly get the following error:</p>
  
  <pre><code>Error: connect ECONNREFUSED
   at Object.exports._errnoException (util.js:1022:11)
   at exports._exceptionWithHostPort (util.js:1045:20)
   at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1087:14)
  </code></pre>
  
  <p>I have installed node.js and did cmd commands: npm install and node index. What am I doing wrong? My code is as follow for the index file:</p>
  
  <pre><code>var config = require('./config');
  
  // ******************* WebSocket server ******************* 
  
  var wsClients = {};
  var WebSocket = require('ws');
  var webSocketServer = new WebSocket.Server({ 'host': config.webSocketHost,'port': config.webSocketPort }, function(){
      console.log('WebSocket listening '+config.webSocketHost+' on port '+config.webSocketPort+'.');
  });
  
  webSocketServer.on('connection', function(cws) {
      var id = Math.random();
      wsClients[id] = cws;
      console.log("New connection " + id);
  
      cws.on('close', function() {
          console.log('Connection close ' + id);
          delete wsClients[id];
      });
  
      cws.on('error', function() {
          console.log('Connection error ' + id);
          delete wsClients[id];
      });
  });
  
  webSocketServer.on('message', function(data){
      console.log(data);
  });
  
  // ******************* Web server *******************
  
  var express = require('express');
  var app = express();
  app.use(express.static('public'));
  
  app.set('views', './views');
  app.set('view engine', 'ejs');
  app.disable('x-powered-by');
  
  app.get('/', function (req, res) {
      res.render('index');
  });
  
  app.use(function(req, res, next) {
      res.status(404).send('Sorry cant find that!');
  });
  
  app.use(function(err, req, res, next) {
      console.error(err.stack);
      res.status(500).send('Something broke!');
  });
  
  var host = config.webHost || process.env.HOST || "127.0.0.1";
  var port = config.webPort || process.env.PORT || 80;
  
  app.listen(port, host, function () {
      console.log('WebServer listening '+config.webHost+' on port '+config.webPort+'.');
  });
  
  // ******************* Twitter bot *******************
  
  var Twitter = require('twitter'); 
  var client = new Twitter(config);
  var stream = client.stream('user');
  
  stream.on('data', function(event, webSocketServer) {
      for (var key in wsClients) {
          wsClients[key].send(JSON.stringify(event));
      }
  }); 
  
  stream.on('error', function(error) {
      throw error;
  });
  </code></pre>