-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
47 lines (35 loc) · 1.19 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
const express = require('express');
const app = express()
const http = require('http').createServer(app);
const io = require('socket.io')(http);
exports.io = io;
require('./sockets/socket')
const cookieParser = require('cookie-parser');
app.use(cookieParser());
const bodyParser = require('body-parser');
app.use(bodyParser.json());
app.set('view engine', 'ejs');
//static
app.use(express.static(__dirname + '/public'));
//view routes
const viewsRoute = require('./views/routes/pagesRoute');
app.use('/', viewsRoute)
//data routers
const mapsRoute = require("./routes/maps/mapRoute");
app.use('/maps', mapsRoute);
const usersRouter = require('./routes/users/usersRoute');
app.use('/users', usersRouter);
//mongooose
const mongoose = require('mongoose');
mongoose.connect('mongodb+srv://tal3:lqPlF8vfOm7Vd2Qt@tal-test1.m39if.mongodb.net/delib-maps', { useNewUrlParser: true, useUnifiedTopology: true });
const db = mongoose.connection;
exports.db = db;
db.on("error", console.error.bind(console, "connection error:"));
db.once("open", () => {
console.log("we are connected to DB");
});
//listen
const port = process.env.PORT || 3002
http.listen(port, () => {
console.log('listening on port', port);
});