{"size": 1541, "ext": "js", "max_stars_repo_path": "server/src/server.js", "max_stars_repo_name": "Samielleuch/Neghlbouh", "max_stars_repo_stars_event_min_datetime": "2020-04-30T06:00:08.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-06T18:49:51.000Z", "max_issues_repo_path": "server/src/server.js", "max_issues_repo_name": "aymenletifi/Neghlbouh", "max_issues_repo_issues_event_min_datetime": "2020-07-20T12:43:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T02:06:05.000Z", "max_forks_repo_path": "server/src/server.js", "max_forks_repo_name": "aymenletifi/Neghlbouh", "max_forks_repo_forks_event_min_datetime": "2020-05-04T19:10:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T21:31:59.000Z"}
{"max_stars_count": 12, "max_issues_count": 15, "max_forks_count": 5, "avg_line_length": 32.1041666667, "max_line_length": 135, "alphanum_fraction": 0.6670992862}
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const cors = require("cors");
const config = require("./config/config");
const logger = require("morgan");

const passport = require("passport");
const server = require("http").Server(app);
const io = require("socket.io")(server);

//Middlewares
app.use(logger("dev"));
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(passport.initialize());
app.set("socketio", io);
io.on("connection", socket => {
  console.log("user connected!!");
  socket.on("disconnect", () => {
    io.emit("user disconnected");
  });
});
//our routes are located in /api/v1/{routefilename}
const route = require("./routers/router")(app);

// error handling
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get("env") === "development" ? err : {};

  // send the error page
  res.status(err.status || 500);
  res.json({ err: { message: err.message } });
});
mongoose
  .connect(
    `mongodb+srv://${config.db.dbUser}:${config.db.dbPassword}@${config.db.dbName}-t4fmt.mongodb.net/test?retryWrites=true&w=majority`,
    { useNewUrlParser: true, useUnifiedTopology: true }
  )
  .then(() => console.log("Connexion à MongoDB réussie !"))
  .catch(() => console.log("Connexion à MongoDB échouée !"));

app.listen(config.port,() => {
  console.log(`Server running at http://${config.hostname}:${config.port}/`);
});