forked from avirupdutta/socketty
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
34 lines (26 loc) · 880 Bytes
/
app.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
require("dotenv").config();
const express = require("express");
const http = require("http");
const mongoose = require("mongoose");
const socket = require("./socket");
const settings = require("./settings");
const routes = require("./routes");
const PORT = process.env.PORT || 3000;
const DATABASE_URL = require("./keys").mongoURI;
// creating the http server
const app = express();
const server = http.Server(app);
mongoose.connect(DATABASE_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
const db = mongoose.connection;
db.on("error", error => console.error(error));
db.once("open", () => console.log("Connected to Database"));
// adding custom settings
settings(app);
// setting up the socket with node http server
socket(server);
// setting up the routes
routes(app);
server.listen(PORT, console.log("Server is running at http://localhost:3000"));