Skip to content

Instantly share code, notes, and snippets.

@ernestofreyreg
Created November 25, 2014 14:27
Show Gist options
  • Save ernestofreyreg/5494fcfc93ba4f454625 to your computer and use it in GitHub Desktop.
Save ernestofreyreg/5494fcfc93ba4f454625 to your computer and use it in GitHub Desktop.
FizzBuzz nodeJS version, for academic/learning purposes.
http = require("http");
url = require("url");
fizzBuzz = function(v) {
return (v%15===0) && "FizzBuzz" || (v%3===0) && "Fizz" || (v%5===0) && "Buzz" || v;
};
http.createServer(function(req, res) {
var i = parseInt(url.parse(req.url).pathname.substring(1));
res.writeHead(200, {"Content-Type": "application/json"});
var v = {};
v[i] = fizzBuzz(i);
res.end(JSON.stringify(v));
}).listen(1337, '127.0.0.1');
console.log("FizzBuzz server running on port 1337");
@ernestofreyreg
Copy link
Author

Just run in on nodeJS like:

$ node main.js

Open your browser and go: http://127.0.0.1:1337/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment