Skip to content

Commit

Permalink
Copilot third commit
Browse files Browse the repository at this point in the history
  • Loading branch information
0x-duelker committed Jan 20, 2025
1 parent d788068 commit de7691e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions comments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Create web server
// 1. Include http module
var http = require('http');
var fs = require('fs');
var url = require('url');
var path = require('path');

// 2. Create server
http.createServer(function (req, res) {
// Parse the request containing file name
var pathname = url.parse(req.url).pathname;
// Print the name of the file for which request is made.
console.log("Request for " + pathname + " received.");

// Read the requested file content from file system
fs.readFile(pathname.substr(1), function (err, data) {
if (err) {
console.log(err);
// HTTP Status: 404 : NOT FOUND
// Content Type: text/plain
res.writeHead(404, { 'Content-Type': 'text/html' });
} else {
// Page found
// HTTP Status: 200 : OK
// Content Type: text/plain
res.writeHead(200, { 'Content-Type': 'text/html' });

// Write the content of the file to response body
res.write(data.toString());
}
// Send the response body
res.end();
});
}).listen(8080);

// Console will print the message
console.log('Server running at http://

0 comments on commit de7691e

Please sign in to comment.