-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·54 lines (43 loc) · 1.31 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const express = require('express');
const morgan = require('morgan');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const cors = require('cors');
const path = require('path');
const fs = require("fs");
require('dotenv').config();
const app = express();
const blogRoutes = require('./routes/blog'),
authRoutes = require('./routes/auth'),
userRoutes = require('./routes/user'),
tagRoutes = require('./routes/tag'),
categoryRoutes = require('./routes/category'),
formRoutes = require('./routes/form');
app.use(morgan('dev'));
app.use(bodyParser.json());
app.use(cookieParser());
app.use(cors());
const mongoose = require('mongoose');
require("dotenv").config({ path: "config.env" });
const DB = process.env.DATABASE.replace(
'<PASSWORD>',
process.env.DATABASE_PASSWORD
);
mongoose
.connect(DB, {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true
})
.then(() => console.log('DB is 👾'));
app.use('/api', blogRoutes);
app.use('/api', authRoutes);
app.use('/api', userRoutes);
app.use('/api', tagRoutes);
app.use('/api', categoryRoutes);
app.use('/api', formRoutes);
const port = process.env.PORT || 8000;
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});