Guest User

Untitled

a guest
Dec 10th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import Fastify from 'fastify';
  2. import IO from 'socket.io';
  3. import _ from 'lodash';
  4.  
  5. function log(message, type = 'info') {
  6. process.stdout.write(
  7. `[${_.toUpper(type)}] ${new Date().toLocaleString()}: ${message}${
  8. message[message.length - 1] === '.' ? '' : '.'
  9. }\n`
  10. );
  11. }
  12.  
  13. const App = Fastify();
  14.  
  15. (async () => {
  16. IO(App.server).on('connection', socket => {
  17. log(`Client connected.`);
  18. socket.on('disconnect', () => {
  19. log(`Client disconnected.`);
  20. });
  21. });
  22.  
  23. try {
  24. await App.listen(1337);
  25. log(`Server is listening on port ${App.server.address().port}.`);
  26. } catch (error) {
  27. log(error, 'error');
  28. process.exit(1);
  29. }
  30. })();
Add Comment
Please, Sign In to add comment