-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
31 lines (25 loc) · 688 Bytes
/
app.js
File metadata and controls
31 lines (25 loc) · 688 Bytes
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
var express = require('express');
var app = express();
var fs = require('fs');
var path = require('path');
const port = process.env.PORT || 3000;
var filename = 'index.html';
//ejs init
app.set("views", __dirname + "/views");
app.set("view engine", "ejs");
app.engine("html", require("ejs").renderFile);
//use public directory
app.use(express.static(path.join(__dirname, 'public')));
//run server
app.listen(port, function(){
console.log('Server is running on port ' + port);
});
//index page
app.get("/", (req, res) => {
res.render("index", {
data : "hello"
});
});
app.get("*", (req, res) => {
res.end('<head><title>404</title></head><body><h1>404 Error!</h1></body>');
});