Created
May 13, 2012 18:51
-
-
Save grantmichaels/2689721 to your computer and use it in GitHub Desktop.
Example node.js script in coffeescript.
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
getDoc = (title, content) -> | |
"""<!DOCTYPE html> | |
<html> | |
<head><title>#{title}</title></head> | |
<body> | |
<h1>#{title}</h1> | |
<p>#{content}</p> | |
</body> | |
</html> | |
""" | |
hostname = '127.0.0.1' | |
port = 8080 | |
http = require 'http' | |
http.createServer (request, response) -> | |
response.writeHead 200, { 'Content-Type': 'text/html' } | |
response.end(getDoc 'Hello', 'Hello, world!') | |
.listen port, hostname | |
console.log "Server listening at http://#{hostname}:#{port}/" |
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
(function() { | |
var getDoc, hostname, http, port; | |
getDoc = function(title, content) { | |
return "<!DOCTYPE html>\n<html>\n<head><title>" + title + "</title></head>\n<body>\n<h1>" + title + "</h1>\n<p>" + content + "</p>\n</body>\n</html>"; | |
}; | |
hostname = '127.0.0.1'; | |
port = 8080; | |
http = require('http'); | |
http.createServer(function(request, response) { | |
response.writeHead(200, { | |
'Content-Type': 'text/html' | |
}); | |
return response.end(getDoc('Hello', 'Hello, world!')); | |
}).listen(port, hostname); | |
console.log("Server listening at http://" + hostname + ":" + port + "/"); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment