-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
52 lines (41 loc) · 1.29 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const express = require('express');
const dotenv = require('dotenv');
const morgan = require('morgan');
const bodyparser = require('body-parser');
const path = require('path');
const connectDB = require('./server/db/connection');
// Express App
const app = express();
// .env and port
dotenv.config({ path: '.env' })
const PORT = process.env.PORT || 8080
//console log request
app.use(morgan('tiny'));
// mongodb connection
connectDB();
// parse request to body-parser
app.use(bodyparser.urlencoded({ extended: true }));
app.use(bodyparser.json());
// set view engine
app.set('view engine', 'ejs')
app.set("views", path.resolve(__dirname, "views"))
// static files
app.use('/css', express.static(path.resolve(__dirname, "public/css")));
app.use('/img', express.static(path.resolve(__dirname, "public/img")));
app.use('/js', express.static(path.resolve(__dirname, "public/js")));
// load routers
app.use('/', require('./server/routes/router'))
// app.use('/add-user',require('./server/routes/router'))
// app.use('/update-user',require('./server/routes/router'))
const start = async () => {
try {
await connectDB();
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
})
}
catch (err) {
console.log(err);
}
}
start();