-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (31 loc) · 1.06 KB
/
index.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
const express = require('express');
const app = express();
const cors = require('cors');
const bodyParser = require('body-parser');
const path = require('path');
require('dotenv').config();
const mongoose = require('mongoose');
const uri = require('./utils/mongoose.js');
const notFound404 = require('./routes/404');
const indexRoutes = require('./routes/index');
app.set('view engine', 'ejs');
//we tell express to look for the views in the views folder
app.set('views', 'views');
app.use(bodyParser.urlencoded({ extended: true }));
//this will serve the static files in the public folder to load styles, etc.
app.use(express.static(path.join(__dirname, 'public')));
app.use(cors());
app.use(indexRoutes);
app.use(notFound404);
mongoose
.connect(uri)
.then((result) => {
console.log('Connected to the database');
app.listen(process.env.PORT || 3000, () => {
console.log(`Your app is listening on port ${process.env.PORT}`);
});
})
.catch((error) => {
console.error('Ooops, something went wrong with connection --- ', error);
});
module.exports = app;