-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
46 lines (34 loc) · 1.21 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
const express = require('express');
const dotenv = require('dotenv');
const morgan = require('morgan');
const bodyparser = require('body-parser');
const pdf = require("html-pdf");
const path = require('path');
const connectDB=require('./server/database/connection')
const app = express();
// import config file for port
dotenv.config({path:'config.env'});
const PORT = process.env.PORT || 8080;
// log request when refresh the webpage
app.use(morgan('tiny'));
// mongodb connection
connectDB();
// parse request to bodyparser
app.use(bodyparser.urlencoded({extended:true}));
// set view engine
app.set("view engine", "ejs");
// used to set different directry for views
// app.set("views".path.resolve(__dirname,"views/ejs"));
// load assets
app.use('/css',express.static(path.resolve(__dirname,"assets/css")));
app.use('/js',express.static(path.resolve(__dirname,"assets/js")));
app.use('/img',express.static(path.resolve(__dirname,"assets/img")));
//Load router
app.use('/',require('./server/routes/router'));
// app.get('/',(req,res)=>{
// res.render('index');
// })
app.listen(PORT,'0.0.0.0',()=>
{
console.log(`server is listening on the http://localhost:${PORT}`);
})