I use the following code which is working as expected, but I want to use it in production. I'm not sure that this is clean code since I'm new to node.js. It would be great if I can get some example how can I write cleaner code.I mean how do I use the config to read the values, there is better way?How do I use the onListening?/** * Module dependencies. */var app = require('../app');var debug = require('debug')('blog-twitter:server');var http = require('http');var os=require('os');var request=require('superagent')/** * Get port from environment and store in Express. */var port = normalizePort(process.env.PORT || '8062');app.set('port', port);/** * Create HTTP server. *///var io=require('express-socket.io');var server = http.createServer(app);var io=require('socket.io').listen(server);var Twitter=require('twitter');var cfg = require('../config.json');//console.log(cfg.twitter);/***Create a twitter client to use AUTH credentials defined*in config.json file*/var client=new Twitter({  consumer_key: cfg.twitter.consumer_key,  consumer_secret: cfg.twitter.consumer_secret,  access_token_key: cfg.twitter.access_token_key,  access_token_secret: cfg.twitter.access_token_secret});/**Bind to twitter public streaming API*/var stream=client.stream('statuses/filter',{track:Javascript});/***Create twitter stream, when a tweet is available, *get its embeded format and emit that to the server.*/stream.on(data, function(data){  console.log(data.id_str);  var tweet_id=https://api.twitter.com/1.1/statuses/oembed.json?id=+data.id_str;  //console.log(data);  //console.log(ID:,tweet_id);  request.get(tweet_id)  .end(function(err,res){      if(err){        console.log(Error: +err);      }else{        //console.log(res.body);        io.emit('tweet',res.body);      }  });  //console.log(Tweet: ,data);});stream.on('error', function(err){  console.log(Error retrieving tweets: +err);});io.on('connection', function(client){  client.on(join, function(data){    console.log(data);  });  client.emit(join,{message:Welcome});});/** * Listen on provided port, on all network interfaces. */server.listen(port);server.on('error', onError);server.on('listening', onListening);/** * Normalize a port into a number, string, or false. */function normalizePort(val) {  var port = parseInt(val, 10);  if (isNaN(port)) {    // named pipe    return val;  }  if (port >= 0) {    // port number    return port;  }  return false;}/** * Event listener for HTTP server error event. */function onError(error) {  if (error.syscall !== 'listen') {    throw error;  }  var bind = typeof port === 'string'    ? 'Pipe ' + port    : 'Port ' + port;  // handle specific listen errors with friendly messages  switch (error.code) {    case 'EACCES':      console.error(bind + ' requires elevated privileges');      process.exit(1);      break;    case 'EADDRINUSE':      console.error(bind + ' is already in use');      process.exit(1);      break;    default:      throw error;  }}/** * Event listener for HTTP server listening event. */function onListening() {  var addr = server.address();  var serverName=cfg.server;  var runServer=`http://localhost:8060/service/tweets/${server.address().port}`;  if(cfg.hosted){    runServer=`http://${serverName}/service/tweets/${server.address().port}`;  }  console.log( Server on:,runServer)  var bind = typeof addr === 'string'    ? 'pipe ' + addr    : 'port ' + addr.port;  debug('Listening on ' + bind);  var expose=()=>{      request.put(blogServer,(err,res)=>{        if(err){          console.log(Error:,err);        }      });  }  setInterval(expose,15*1000);}
Using node bin/www with twits
javascript;beginner;node.js;express.js;twitter