-
Notifications
You must be signed in to change notification settings - Fork 8
/
server.js
39 lines (28 loc) · 900 Bytes
/
server.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
const express = require('express');
const morgan = require('morgan');
const path = require('path');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const dotenv = require('dotenv');
const authRoute = require('./Routes/routes');
const cors = require('cors')
dotenv.config();
//initialize express.
const app = express();
//connect to db
mongoose.connect(
process.env.DB_CONNECT, { useUnifiedTopology: true, useNewUrlParser: true },
() => console.log('connected to db')
);
// Initialize variables.
const port = 3001; // process.env.PORT || 3000;
// Configure morgan module to log all requests.
app.use(morgan('dev'));
app.use(cors());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
//set route middleware
app.use('/', authRoute);
// Start the server.
app.listen(port);
console.log('Listening on port ' + port + '...');