Skip to content

Instantly share code, notes, and snippets.

@grantmichaels
Created May 13, 2012 18:51
Show Gist options
  • Save grantmichaels/2689721 to your computer and use it in GitHub Desktop.
Save grantmichaels/2689721 to your computer and use it in GitHub Desktop.
Example node.js script in coffeescript.
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}/"
(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