From 43cae09417be9a74b61867f58ea0e7192dc265d2 Mon Sep 17 00:00:00 2001 From: tzvi Date: Fri, 21 Jul 2017 13:40:33 -0400 Subject: [PATCH 1/3] servinf html --- app.js | 19 +++++++++++++++++++ public/index.html | 10 ++++++++++ 2 files changed, 29 insertions(+) create mode 100644 app.js create mode 100644 public/index.html diff --git a/app.js b/app.js new file mode 100644 index 0000000..9f269e8 --- /dev/null +++ b/app.js @@ -0,0 +1,19 @@ +let http = require('http'); +let fs = require('fs'); + +let port = 3000; +let host = 'localhost'; + + + +let server = http.createServer((req, res) => { + fs.readFile('./public/index.html', 'utf-8', function( err, data ) { + res.writeHead (200, {'Content-Type': 'text/html' }); + res.end(data); + }); +}) + +server.listen(port, host, function(){ + console.log( `Server Running at ${host} ${port}` ); +}); + diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..e0baab5 --- /dev/null +++ b/public/index.html @@ -0,0 +1,10 @@ + + + + + + + +

Hello World

+ + \ No newline at end of file From e0d9c329d122ba7187121397626242e4993562fc Mon Sep 17 00:00:00 2001 From: tzvi Date: Fri, 21 Jul 2017 13:58:11 -0400 Subject: [PATCH 2/3] name --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 29b1d71..4b7d3cd 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # assignment_build_a_nodejs_server Building your first Node.js server and exploring the request and response objects + +Tzvi Seliger From 4cf5262073eab9966d6d9a3dd7e7b2a8e893bd10 Mon Sep 17 00:00:00 2001 From: tzvi Date: Fri, 17 Nov 2017 07:30:51 -0500 Subject: [PATCH 3/3] all working --- app.js | 10 +++++++--- public/index.html | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 9f269e8..ec68a12 100644 --- a/app.js +++ b/app.js @@ -4,12 +4,16 @@ let fs = require('fs'); let port = 3000; let host = 'localhost'; - - let server = http.createServer((req, res) => { fs.readFile('./public/index.html', 'utf-8', function( err, data ) { + res.writeHead (200, {'Content-Type': 'text/html' }); - res.end(data); + + res.end( + data + .replace(/{{ res }}/, JSON.stringify(res.statusMessage+" "+res.statusCode+" "+res._header, null, 2) ) + .replace(/{{ req }}/, JSON.stringify(req.url+" "+req.method+" "+req.httpVersion+" "+req.headers, null, 2)) + ); }); }) diff --git a/public/index.html b/public/index.html index e0baab5..a27e021 100644 --- a/public/index.html +++ b/public/index.html @@ -6,5 +6,21 @@

Hello World

+

Request:

+ +
+		{{ req }}
+	
+ +

Response:

+ +
+		{{ res }}
+	
+
+ + + +
\ No newline at end of file