@Lokraan/

petpet

Nodejs

No description

fork
loading
Files
  • index.js
  • config
  • src
  • static
  • .gitignore
  • inde.js
  • package-lock.json
  • package.json
  • README.md
  • website
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const { app: { port } } = require("./config/config");
const express = require("express");
const app = express();
const server = app.listen(port);

const db = require("./src/db.js");

let socketio = require('socket.io');
let io = socketio(server);

const router = require("./src/routes/index");
router(app);

app.set("views", "./src/views");
app.set("view engine", "pug");

console.log("Listening on " + port);

// Sockets
let cons = 0;
io.on('connection', socket => {
  cons++;
  console.log('Client Connected (' + cons + ')');

  // Send Reports
  db.getLostReports((reports) => {
    socket.emit('Lost Reports', reports ? reports : []);
  });

  io.on('disconnect', () => {
    console.log('Client Disconnected (' + cons + ')');
    cons--;
  });
});
node v10.16.0