Skip to content

Instantly share code, notes, and snippets.

@nelsonic
Created April 19, 2013 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nelsonic/5420539 to your computer and use it in GitHub Desktop.
Save nelsonic/5420539 to your computer and use it in GitHub Desktop.
A Basic Hello World NodeJS script in CoffeeScript. This can be a two or three line script. but i've done it this way to explain the components.
http = require 'http' # Require the HTTP Core NodeJS Module (notice the lack of brackets)
port = process.env.PORT or 4000 # The TCP port you want to "listen" on (see line #6) allows the system (e.g. Heroku to set it or uses 4000 on local machine)
http.createServer (req, res) -> # Creates a basic Web Server and gives you the REQuest and RESponse objects to the function
res.writeHead 200 # Write the HTTP Status Code "200" ("All OK") in the RESponse to the client (browser)
res.end 'Hello World!' # End the RESponse with the message 'Hello World'
.listen port # the dot before the word listen means "Chain" to the createServer and listen on the port
console.log "Visit: http://localhost:#{port}" # console.log allows you to write a "Note-to-self" on the command line.
### if any of the above is unclear, Google it! (or msg me for a personal Tutorial: https://twitter.com/nelsonic) ###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment