forked from iamrahulmahato/master-web-development
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
25 lines (20 loc) · 743 Bytes
/
App.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
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const forumRoutes = require('./routes/forum');
const app = express();
const PORT = process.env.PORT || 3000;
// Middleware
app.use(bodyParser.urlencoded({ extended: true }));
app.set('view engine', 'ejs');
app.use(express.static('public'));
// MongoDB connection
mongoose.connect('mongodb://localhost:27017/forumDB', { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => console.log('MongoDB connected'))
.catch(err => console.error(err));
// Routes
app.use('/', forumRoutes);
// Start the server
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});