From a8fcaa6f18ab798e69b074bff4750bec8b288370 Mon Sep 17 00:00:00 2001 From: Kenny Kottenstette Date: Fri, 7 Sep 2018 20:02:07 -0700 Subject: [PATCH 1/2] begin outputting html --- app.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 app.js diff --git a/app.js b/app.js new file mode 100644 index 0000000..ac05753 --- /dev/null +++ b/app.js @@ -0,0 +1,14 @@ +var http = require('http'); + +var port = 3000; +var host = 'localhost'; + +var server = http.createServer(function(req, res){ + res.statusCode = 200; + res.setHeader('Content-Type', 'text/plain'); + res.end("HELLO WORLD"); +}); + +server.listen(port, host, function(){ + console.log(`Listening at http://${host}:${port}`); +}); From 806a308d3efadba75ecaa592362ca2d713768231 Mon Sep 17 00:00:00 2001 From: Kenny Kottenstette Date: Fri, 7 Sep 2018 20:07:15 -0700 Subject: [PATCH 2/2] begin outputting request and response data --- app.js | 18 +++++++++++++++--- public/index.html | 10 ++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 public/index.html diff --git a/app.js b/app.js index ac05753..54b7fe1 100644 --- a/app.js +++ b/app.js @@ -1,12 +1,24 @@ var http = require('http'); +var fs = require('fs'); var port = 3000; var host = 'localhost'; var server = http.createServer(function(req, res){ - res.statusCode = 200; - res.setHeader('Content-Type', 'text/plain'); - res.end("HELLO WORLD"); + 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); + } + }) + + + // res.statusCode = 200; + // res.setHeader('Content-Type', 'text/plain'); + // res.end("HELLO WORLD"); }); server.listen(port, host, function(){ diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..6a299a4 --- /dev/null +++ b/public/index.html @@ -0,0 +1,10 @@ + + + + + + + +

html file!

+ +