Created
November 25, 2014 14:27
-
-
Save ernestofreyreg/5494fcfc93ba4f454625 to your computer and use it in GitHub Desktop.
FizzBuzz nodeJS version, for academic/learning purposes.
This file contains hidden or 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
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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just run in on nodeJS like:
$ node main.js
Open your browser and go: http://127.0.0.1:1337/