-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
38 lines (21 loc) · 747 Bytes
/
app.js
File metadata and controls
38 lines (21 loc) · 747 Bytes
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
const express = require('express');
const morgan = require('morgan');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const userRouter = require('./routes/users');
const db = require('./configuration/key').mongoURI;
mongoose.Promise = global.Promise;
mongoose.connect(db, { useNewUrlParser: true })
.then( () => console.log("MongoDB Connected ..."))
.catch(err => console.log(err));
mongoose.set('useCreateIndex', true)
const app = express();
// Middlewares
app.use(morgan('dev'));
app.use(bodyParser.json());
// Routes
app.use('/users', userRouter);
// Start the server
const PORT = process.env.PORT || 3000;
app.listen(PORT);
console.log(`Server listening at http://localhost:${PORT}`);