Created
April 11, 2014 07:14
-
-
Save davesag/10446082 to your computer and use it in GitHub Desktop.
A very simple hello-world http server in Coffeescript
This file contains 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
### | |
A hello world server written in Coffeescript | |
Step 0: Install Node.js `brew install node` | |
Step 1: Install Coffeescript `npm install -g coffee-script` | |
Step 2: `coffee -c hello-world-server.coffee` | |
Step 3: `node hello-world-server` | |
Step 4: point your browser of choice at http://localhost:8000 | |
… | |
Profit! | |
`control-c` to quit. | |
Thrown together hastily by Dave Sag <[email protected]> | |
### | |
http = require "http" | |
http.createServer( (req, res) -> | |
body = "Hello World!" | |
headers = | |
'Content-Type': "text/plain" | |
'Content-Length': body.length | |
res.writeHead 200, headers | |
res.end body, 'utf8' | |
).listen 8000 | |
console.log "Server running at http://127.0.0.1:8000/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment