-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
38 lines (29 loc) · 847 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
38
const path = require('path');
const express = require('express');
const dotenv = require('dotenv');
const morgan = require('morgan');
const exphbs = require('express-handlebars');
const connectDB = require('./config/db');
// Load config
dotenv.config({ path: './config/config.env' });
connectDB();
// Initialized app
const app = express();
// Logging
if (process.env.NODE_ENV === 'development') {
app.use(morgan('dev'));
}
// Handlebars Template Engine
app.engine('.hbs', exphbs({ defaultLayout: 'main', extname: '.hbs' }));
app.set('view engine', '.hbs');
// Static Folders
app.use(express.static(path.join(__dirname, 'public')));
// Routes
app.use('/', require('./routes/index'));
const PORT = process.env.PORT || 3000;
app.listen(
PORT,
console.log(
`Server is running in ${process.env.NODE_ENV} mode on port ${PORT}`
)
);