Skip to content

Instantly share code, notes, and snippets.

@marocchino
Created October 22, 2011 13:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marocchino/1305972 to your computer and use it in GitHub Desktop.
Save marocchino/1305972 to your computer and use it in GitHub Desktop.
nodejs - simple calculator server
sys = require 'sys'
http = require 'http'
host = "0.0.0.0"
port = 3000
http.createServer (request,response) ->
[_, op, a, b] = request.url.split "/"
a = parseInt a
b = parseInt b
result = {
"add": (a, b) -> a + b
"sub": (a, b) -> a - b
"mul": (a, b) -> a * b
"div": (a, b) -> a / b
}[op]? a, b
response.writeHead 200, 'Content-Type': 'text/html'
response.end "<h2> #{result} </h2>"
.listen port, host
sys.puts "Server running at http://#{host}:#{port}"
@Himani101
Copy link

is this code is write

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