-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
34 lines (28 loc) · 1.04 KB
/
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 morgan = require('morgan');
const bodyParser = require('body-parser');
const MongoClient = require('mongodb').MongoClient;
const app = express();
const port = process.env.PORT || 8000;
const mongoHost = process.env.MONGO_HOST;
const mongoPort = process.env.MONGO_PORT || '27017';
const mongoDBName = process.env.MONGO_DATABASE;
const mongoUser = process.env.MONGO_USER;
const mongoPassword = process.env.MONGO_PASSWORD;
const mongoURL = `mongodb://${mongoUser}:${mongoPassword}@${mongoHost}:${mongoPort}/${mongoDBName}`
app.use(morgan('dev'));
app.use(bodyParser.json());
app.use('/', require('./routes'));
app.use('*', function (req, res, next) {
res.status(404).json({
error: "Requested resource " + req.originalUrl + " does not exist"
});
});
MongoClient.connect(mongoURL, function (err, client) {
if (!err) {
app.locals.mongoDB = client.db(mongoDBName);
app.listen(port, function() {
console.log("== Server is running on port", port);
});
}
});