From 2942795b4d937dc1ade4d2245ced4a9332d4f1c8 Mon Sep 17 00:00:00 2001 From: "Brian P. Gallagher" Date: Wed, 4 Jul 2018 15:53:33 -0400 Subject: [PATCH 1/4] name added --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 29b1d71..ed27421 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 + +Brian Gallagher From 62d0abe5f7347072b633f7b95319d11f013cf11a Mon Sep 17 00:00:00 2001 From: "Brian P. Gallagher" Date: Fri, 6 Jul 2018 01:04:59 -0400 Subject: [PATCH 2/4] setting up http server --- public/index.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 public/index.html diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..08fdc5d --- /dev/null +++ b/public/index.html @@ -0,0 +1,12 @@ + + + + + + + Hello Node.js Server! + + +

Hello Node.js Server!

+ + From 0b34f64dcd39999350805f6c5a54b9b5de9d6d2d Mon Sep 17 00:00:00 2001 From: "Brian P. Gallagher" Date: Fri, 6 Jul 2018 01:06:19 -0400 Subject: [PATCH 3/4] setting up http server --- app.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 app.js diff --git a/app.js b/app.js new file mode 100644 index 0000000..fff5327 --- /dev/null +++ b/app.js @@ -0,0 +1,23 @@ +var http = require('http'); + +var port = 3000; +var host = 'localhost'; + + +var server = http.createServer(function(req, res) { + fs.readFile('./public/index.html', 'utf8', function(err, data) { + if (err) { + res.writeHead(404); + res.end("404 Not Found"); + } else { + res.writeHead(200, { + "Content-Type": "text/html" + }); + res.end(data); + } + }); +}); + +server.listen(port, host, function() { + console.log(`Listening at http://${ host }:${ port }`); +}); From fa81d9ae7bea717e93a479a90dbb4f9a76005418 Mon Sep 17 00:00:00 2001 From: "Brian P. Gallagher" Date: Fri, 6 Jul 2018 02:14:12 -0400 Subject: [PATCH 4/4] need solution. we didnt learn the last part. cant find solution online. --- app.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app.js b/app.js index fff5327..413762e 100644 --- a/app.js +++ b/app.js @@ -1,4 +1,5 @@ var http = require('http'); +var fs = require('fs'); var port = 3000; var host = 'localhost'; @@ -12,6 +13,8 @@ var server = http.createServer(function(req, res) { } else { res.writeHead(200, { "Content-Type": "text/html" + console.log(String.prototype.replace(req)); + console.log(JSON.stringify(req.pre)); }); res.end(data); }