-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
29 lines (23 loc) · 804 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
require('dotenv').config();
const cors = require('cors');
const express = require('express');
const app = express();
const mongoose = require('mongoose');
mongoose.connect(process.env.DATABASE_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
});
const db = mongoose.connection;
db.on('error', (error) => console.log(error));
db.once('open', () => console.log('Database connected'));
app.use(cors({ origin: '*' }));
// added a middleware,with the use of this
//the coming data inside body of request gets
//parsed automatically.
app.use(express.json());
app.use(express.urlencoded());
const userIpRouter = require('./routes/userIp');
app.use('/user', userIpRouter);
app.listen(process.env.PORT || 3001, () => console.log('Server Started'));