Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. const express = require('express');
  2.  
  3. const app = express();
  4.  
  5. app.get('/', (req, res) => res.json({ ping: true }));
  6.  
  7. const server = app.listen(3000, () => {
  8. console.log('Running…');
  9. });
  10.  
  11. setInterval(() => server.getConnections(
  12. (err, connections) => console.log(`${connections} connections currently open`)
  13. ), 1000);
  14.  
  15. process.on('SIGTERM', () => shutDown(server));
  16. process.on('SIGINT', () => shutDown(server));
  17.  
  18. function shutDown() {
  19. console.log('Received kill signal, shutting down gracefully');
  20. server.close(() => {
  21. console.log('Closed out remaining connections');
  22. process.exit(0);
  23. });
  24.  
  25. setTimeout(() => {
  26. console.error('Could not close connections in time, forcefully shutting down');
  27. process.exit(1);
  28. }, 10000);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement