-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
33 lines (28 loc) · 814 Bytes
/
server.js
File metadata and controls
33 lines (28 loc) · 814 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
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const mongodb = require('./data/database');
const app = express();
const port = process.env.PORT || 3001;
// Middleware
app.use(bodyParser.json());
app.use((req, res, next) => {
res.setHeader(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept, Z-Key'
);
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
next();
});
// Routes
app.use('/', require('./routes'));
// Initialize DB and start server
mongodb.initDb((err) => {
if (err) {
console.error(err);
} else {
app.listen(port, () => {
console.log(`Database is listening and node Running on port ${port}`);
});
}
});