-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
43 lines (33 loc) · 980 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
35
36
37
38
39
40
41
42
43
const express = require('express')
const bodyParser = require('body-parser')
const mongoose = require('mongoose');
const dotenv = require('dotenv')
// express app
const app = express()
// import routes
const authRoutes = require('./routes/auth')
const postRoute = require('./routes/posts')
dotenv.config()
// body parser
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
// database connection
mongoose.connect( process.env.DB_CONNECT, {
useNewUrlParser: true,
useUnifiedTopology: true
});
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
// we're connected!
console.log('------------------Database is connected!--------------');
});
// route middlewares
app.use('/api/user', authRoutes);
app.use('/api/posts', postRoute)
// port setting
const PORT = 3000;
app.listen(PORT, () => {
console.log('Server is up and running');
})