-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
37 lines (30 loc) · 858 Bytes
/
server.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
35
36
37
import express from 'express';
import mongoose from 'mongoose';
import cors from 'cors';
import {readdirSync} from 'fs';
const morgan = require('morgan');
require('dotenv').config();
const app = express();
// //db
mongoose
.connect(process.env.DATABASE, {
// useNewUrlParser: true,
// useUnifiedTopology: true,
// dbName: 'myFirstDatabase'
})
.then(() => console.log('DB Connected'))
.catch((err) => console.log ('DB ERROR', err));
//middleware
app.use(express.json({limit: '5mb'}));
app.use (
cors({
origin: [process.env.CLIENT_URL]
})
);
//autoload routes
// app.get('/api/register', (req, res) => {
// res.send('Hey man')
// });
readdirSync('./routes').map((r) => app.use('/api', require(`./routes/${r}`)))
const port = process.env.PORT || 8000
app.listen(port, () => console.log(`Port is running on port ${port}`));