Skip to content

Commit 2bcd8cf

Browse files
committed
Initialize repo
0 parents  commit 2bcd8cf

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

package.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "web-server",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"express": "^4.13.2"
13+
}
14+
}

public/index.html

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE = html>
2+
<html>
3+
<head>
4+
<meta charset ="utf-8"/>
5+
<title>My App</title>
6+
</head>
7+
<body>
8+
<h1>Hello Express.js</h1>
9+
</body>
10+
</html>

server.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var express = require('express');
2+
var app = express();
3+
var PORT = 3000;
4+
var middleware = {
5+
requireAuthentication: function(req,res,next){
6+
console.log("private route hit");
7+
next();
8+
},
9+
logger: function(req,res,next){
10+
var date = new Date().toString();
11+
console.log("Request: " + date + " " +req.method + ' '+ req.originalUrl)
12+
next();
13+
}
14+
}
15+
app.use(middleware.logger);
16+
17+
app.get('/about',middleware.requireAuthentication, function(req, res){
18+
res.send("About Us");
19+
});
20+
21+
app.use(express.static(__dirname + "/public"));
22+
app.listen(PORT, function(){
23+
console.log("Express server started at port "+ PORT);
24+
});
25+

0 commit comments

Comments
 (0)