-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (29 loc) · 782 Bytes
/
index.js
File metadata and controls
34 lines (29 loc) · 782 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
34
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const app = express();
const cors = require('cors');
const mongoose = require('mongoose');
// Local packages
const ErrorController = require('./controllers/error');
const Router = require('./routes/admin');
const AuthRouter = require('./routes/auth');
app.use(cors());
app.use(bodyParser.json());
app.use(
bodyParser.urlencoded({
extended: true,
})
);
app.use(express.static(path.join(__dirname, 'public')));
app.use('/api/admin', Router);
app.use('/api', AuthRouter);
app.use(ErrorController.error404);
mongoose
.connect('mongodb://localhost:27017/my_database')
.then(() => {
app.listen(8000);
})
.catch((err) => {
throw new Error(err);
});