-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.js
46 lines (36 loc) · 1.27 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
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config();
}
const express = require('express');
const bodyParser = require('body-parser');
const ejs = require('ejs');
const mongoose = require('mongoose');
const methodOverride = require('method-override');
const app = express();
app.set('view engine', 'ejs');
app.use(express.static('public'));
const path = require('path');
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(methodOverride('_method'));
mongoose.connect(process.env.DATABASE_URL, {
useNewUrlParser: true,
useUnifiedTopology: true
});
// mongoose.connect("mongodb://localhost:27017/verifmeDB");
const db = mongoose.connection;
db.on('error', (err) => console.log(err));
db.once('open', () => console.log('Connected to Database...'));
// Home page route
const indexRouter = require('./routes/index');
app.use('/', indexRouter);
// Start page
const startRouter = require('./routes/start');
app.use('/start', startRouter);
// Posts
const articleRouter = require('./routes/articles');
app.use('/articles', articleRouter);
// Posts
const commentRouter = require('./routes/comments');
app.use('/comments', commentRouter);
app.listen(process.env.PORT || 3000, () => console.log('Server Started...'));