-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
37 lines (24 loc) · 852 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
26
27
28
29
30
31
32
33
34
35
36
37
const express = require('express');
const expressLayouts = require('express-layouts');
const routes = require('./routes');
const apiRoutes = require('./routes/api_routes');
const connectToMongo = require('./helpers/connectToMongo');
const app = express();
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config({ path: './.env' });
}
// Views engine
app.set('view engine', 'ejs');
app.set('views', __dirname + '/views');
app.set('layout', 'layouts/layout');
app.use(expressLayouts);
// Static files
app.use(express.static('public'));
app.use(express.urlencoded({ extended: false }));
app.use(express.json())
connectToMongo(process.env.MONGO_URI);
app.use('/', routes);
// API Endpoints
app.use('/api', apiRoutes);
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`App listening on port ${PORT}`));