heroku-examples/node-concurrency

Followed the sample and getting Error about PORT in use

tgmerritt opened this issue · 0 comments

Continually getting this port conflict error:

Error: listen EADDRINUSE: address already in use :::55475

Using this basic code to start:


 const throng = require('throng')
 const WORKERS = process.env.WEB_CONCURRENCY || 5

...

function startProdApp() {
  var app = require('../app');
  let port = process.env.PORT;
  function onListen() {
    console.log('Listening on', port)
  }
  app.listen(port, onListen)
}

if(process.env.NODE_ENV === 'development'){
  startApp()
} else {
  throng({
       master: startProdApp(),
       worker: startProdApp(),
       count: WORKERS,
       lifetime: Infinity
   })
}

Heroku won't fork it appears - throng requires declaring the master and worker functions now https://github.com/hunterloftis/throng/blob/master/examples/complex.js

  if (typeof worker !== 'function') {
    throw new Error('Start function required');
  }