const express = require('express');
const { createServer } = require('node:http');
const { Server } = require('socket.io');

const app = express();
const server = createServer(app);
const io = new Server(server);


const port = 3000


app.set('view engine', 'pug')
app.use(express.static('assets'))

app.get('/', (req, res) => {
  // res.send('Hello World!')
  // res.render('index', { title: 'Hey', message: 'Hello there PUG!' })
  res.sendFile('main.html');
})

io.on('connection', (socket) => {
  console.log('a user connected');
  let speed = 0.1;
  setInterval(() => {
    speed+=0.1;
    socket.emit('speed', speed);
  }, 2000);
});

server.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})