Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Fastify from 'fastify';
- import IO from 'socket.io';
- import _ from 'lodash';
- function log(message, type = 'info') {
- process.stdout.write(
- `[${_.toUpper(type)}] ${new Date().toLocaleString()}: ${message}${
- message[message.length - 1] === '.' ? '' : '.'
- }\n`
- );
- }
- const App = Fastify();
- (async () => {
- IO(App.server).on('connection', socket => {
- log(`Client connected.`);
- socket.on('disconnect', () => {
- log(`Client disconnected.`);
- });
- });
- try {
- await App.listen(1337);
- log(`Server is listening on port ${App.server.address().port}.`);
- } catch (error) {
- log(error, 'error');
- process.exit(1);
- }
- })();
Add Comment
Please, Sign In to add comment