-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (27 loc) · 806 Bytes
/
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
35
36
37
38
39
40
41
42
43
44
// expressjs app with EJS template engine and static files
// import modules
const express = require('express');
const fs = require('fs');
const bodyParser = require('body-parser');
const ejs = require('ejs');
// create express app
const app = express();
// set view engine
app.set('view engine', 'ejs');
// set static files
app.use('/static', express.static('static'));
// set body parser
app.use(bodyParser.urlencoded({ extended: true }));
// cookie parser
app.use(require('cookie-parser')());
// handler
fs.readdirSync('./routes').forEach((file) => {
require(`./routes/${file}`)(app);
})
app.use("*", (req, res) => {
res.status(404).render('404');
})
// listen
app.listen(process.env.PORT || 3000, () => {
console.log('Server is running on port ' + (process.env.PORT || 3000));
})