-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
34 lines (26 loc) · 832 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
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const app = express();
// Connecting to MongoDB database.
const {
mongoURI
} = require('./config/db');
mongoose.connect(mongoURI, {
useNewUrlParser: true
}).then(() => console.log('Connected to MongoDB Server...'))
.catch(err => console.log(`Error connecting to MongoDB server...${err}`));
// BodyParser Middleware.
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(bodyParser.json());
// Importing routes.
const api = require('./routes/route');
app.get('/', (req, res) => {
res.send(`Listening on port: ${port}`);
});
// Using routes.
app.use('/api', api);
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Server started on port: ${port}`));