Created
July 4, 2019 09:17
-
-
Save RayanBassetti/61b73131cdf27cfd6acd95ef60aa7c82 to your computer and use it in GitHub Desktop.
Odin - NodeJS Project #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const fs = require('fs'); | |
const url = require('url'); | |
http.createServer(function(req, res) { | |
var q = url.parse(req.url, true); | |
var filename = "." + q.pathname; | |
if(filename == "./") { | |
fs.readFile('index.html', function(err, data) { | |
res.writeHead(200, {'Content-Type': 'text/html'}); | |
res.write(data); | |
res.end(); // end the response | |
}); | |
} | |
else if(filename == "./contact-me") { | |
fs.readFile('contact-me.html', function(err, data) { | |
res.writeHead(200, {'Content-Type': 'text/html'}); | |
res.write(data); | |
res.end(); // end the response | |
}); | |
} | |
else if(filename == "./about") { | |
fs.readFile('about.html', function(err, data) { | |
res.writeHead(200, {'Content-Type': 'text/html'}); | |
res.write(data); | |
res.end(); // end the response | |
}); | |
} | |
else { | |
fs.readFile('404.html', function(err, data) { | |
res.writeHead(404, {'Content-Type': 'text/html'}); | |
res.write(data); | |
res.end(); // end the response | |
}); | |
} | |
}).listen(8080, console.log("Server running at localhost:8080.")); // the server object listens on port 8080 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment