zubaer-githubapi
Version:
Get a list of repository of a github user
32 lines (30 loc) • 981 B
JavaScript
var http = require("http");
var fs = require("fs");
console.log("Starting server...");
config = JSON.parse(fs.readFileSync('./files/config.json'));
var host = config.host;
var port = config.port;
var server = http.createServer(function(request, response) {
console.log("Recieved request: "+request.url);
fs.readFile("./public/"+request.url, function(error, data) {
if(error) {
response.writeHead(404, {'Content-Type': 'text/plain'});
response.end("Sorry! the page wasn't found.");
} else {
response.writeHead(200, {'Content-Type': 'text/html'});
response.end(data);
}
});
});
server.listen(port, host, function() {
console.log("Listening "+host+":"+port);
});
fs.watch('./files/config.json', function() {
config = JSON.parse(fs.readFileSync('./files/config.json'));
var host = config.host;
var port = config.port;
server.close();
server.listen(port, host, function() {
console.log("Listening "+host+":"+port);
});
});