-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (32 loc) · 1.13 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
const request = require('request');
const mongoose = require('mongoose');
const express = require('express');
const app = express();
// const MongoClient = require('mongodb').MongoClient;
const port = process.env.PORT || 9600;
require('dotenv/config');
const bodyParser = require('body-parser');
const cors = require('cors');
app.use(express.json());
app.use(express.urlencoded({extended: true}));
app.use(cors());
// Import Routes
const postsRoutes = require('./routes/postsRoute');
app.use('/posts', postsRoutes)
// DB connection
// const client = new MongoClient(process.env.DB_CONNECTION, { useNewUrlParser: true, useUnifiedTopology: true });
// client.connect(err => {
// if(err) throw err;
// // const collection = client.db("test").collection("devices");
// // perform actions on the collection object
// console.log('Database is connected!')
// // client.close();
// });
mongoose.connect(process.env.DB_CONNECTION, { useNewUrlParser: true}, (err)=>{
if(err) throw err;
console.log('Database is connected!!!!!')
});
app.listen(port, function(err){
if(err) throw err;
console.log(`Server is running on port ${port}`);
})