-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
24 lines (19 loc) · 731 Bytes
/
app.js
File metadata and controls
24 lines (19 loc) · 731 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
import express from 'express';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import index from './routes/index';
import dotenv from 'dotenv';
dotenv.config({silent: true});
const db = mongoose.connection;
const app = express();
const port = process.env.PORT || 8000;
const dbuser = process.env.DB_USER || 'localhost';
const dbpass = process.env.DB_PASS || '123456';
mongoose.connect(`mongodb://${dbuser}:${dbpass}@ds235788.mlab.com:35788/got_db`);
db.on('error', console.error.bind(console, 'connection error:'));
app.use('/', index);
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.listen(port, () => {
console.log(`Express server listening at port ${port}`)
});