www 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env node
  2. /**
  3. * Module dependencies.
  4. */
  5. var app = require('../app');
  6. var debug = require('debug')('slack-invite-automation:server');
  7. var http = require('http');
  8. /**
  9. * Get port from environment and store in Express.
  10. */
  11. var port = parseInt(process.env.PORT, 10) || 3000;
  12. app.set('port', port);
  13. /**
  14. * Create HTTP server.
  15. */
  16. var server = http.createServer(app);
  17. /**
  18. * Listen on provided port, on all network interfaces.
  19. */
  20. server.listen(port);
  21. server.on('error', onError);
  22. server.on('listening', onListening);
  23. /**
  24. * Event listener for HTTP server "error" event.
  25. */
  26. function onError(error) {
  27. if (error.syscall !== 'listen') {
  28. throw error;
  29. }
  30. // handle specific listen errors with friendly messages
  31. switch (error.code) {
  32. case 'EACCES':
  33. console.error('Port ' + port + ' requires elevated privileges');
  34. process.exit(1);
  35. break;
  36. case 'EADDRINUSE':
  37. console.error('Port ' + port + ' is already in use');
  38. process.exit(1);
  39. break;
  40. default:
  41. throw error;
  42. }
  43. }
  44. /**
  45. * Event listener for HTTP server "listening" event.
  46. */
  47. function onListening() {
  48. debug('Listening on port ' + server.address().port);
  49. }