forked from johnuman/full-stack-app-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
39 lines (25 loc) · 993 Bytes
/
Copy pathapp.js
File metadata and controls
39 lines (25 loc) · 993 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
37
38
39
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const path = require('path');
const persons = require('./api');
// dbconfig
const db = require('./config').mongoURI;
// define server
const app = express();
// bodyparser middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
//app.use(bodyParser.text());
//app.use(bodyParser.json({ type: 'application/json'}));
// Connect to Mongo
mongoose.connect(db, {useNewUrlParser: true}).then(() => console.log('MongoDB Connected...')).catch(err => console.log(err));
// serve static html file to user
app.get('/',(req, res) => {
res.sendFile(path.join(__dirname,'./index.html'));
});
// api routes
app.use('/api', persons);
const port = process.env.PORT || 5000;
// const port = process.env.PORT || (process.argv[2] || 5000);
module.exports = app.listen(5000, () => console.log(`Server started on port http://localhost:${port}`));