-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
26 lines (21 loc) · 798 Bytes
/
index.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
require('dotenv').config();
const fs = require('fs');
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const bodyparser = require('body-parser');
mongoose.connect(process.env.MONGO, {
useNewUrlParser: true,
useUnifiedTopology: true,
}, (err) => console.log(err ? err : 'Connected to mongoDB'));
app.set('json spaces', 1);
app.use(bodyparser.urlencoded({ extended: false }));
app.use(bodyparser.json());
const categories = fs.readdirSync('./src/routes');
categories.forEach((cat) => {
const files = fs.readdirSync(`./src/routes/${cat}`).filter(f => f.endsWith('.js'));
for (const file of files) {
require(`./src/routes/${cat}/${file}`)(app);
}
});
app.listen(3000, () => console.log('server running on port 3000! http://127.0.0.1:3000/'));