atom-community / atom-community/atom-script
Node JS server
- Dominant language
- JavaScript
- Stars
- 730
- Forks
- 264
- PR merge metrics
- No merged PRs in 30d
Description
var http = require('http');
var fs = require('fs');
//404 Response
function send404(res) {
res.writeHead(404, ("Content-Type", "text/plain"));
res.write("Error 404: Page not found!");
}
//create a localhost server on 8888
function onRequest(req, res) {
if (req.method == 'GET' && req.url == '/') {
res.writeHead(200, ("Content-Type", "text/html"));
fs.createReadStream("./Server/main.html").pipe(res);
} else {
send404(res);
}
}
//listens for the request on the browser (& refreshes)
http.createServer(onRequest).listen(8888);
console.log("Localhost:8888 is up & running....");
/* After running the localhost I couldn't kill the server using ctr + C.
Is this not suppose to work or am I missing something? */
Contributor guide
Assessment
This issue has not been assessed yet.