-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
30 lines (26 loc) · 965 Bytes
/
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
const express = require('express');
const cors = require('cors');
const mongoose = require('mongoose');
const cookieParser =require('cookie-parser');
const app = express();
require('dotenv').config();
const eventRoutes = require('./routes/eventRoutes');
const userRoutes = require('./routes/userRoutes');
app.use(express.static('public'));
app.use(cors());
app.use(cookieParser());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
const uri = process.env.ATLAS_URI;
mongoose.connect(uri, { useNewUrlParser :true, useCreateIndex: true, useUnifiedTopology:true}).then(()=>{
console.log("MongoDB connected");
}).catch((error)=>{console.log(error);});
const connection = mongoose.connection;
connection.once('open',()=>{
console.log("MongoDB database connection established successfully");
})
app.use('/events',eventRoutes);
app.use('/users',userRoutes);
app.listen(5000,()=>{
console.log('Server is running on port 5000');
});