The first line is the require() function, which is used to load the coffee-script module that you have just installed. On the second line, we declare the CoffeeScript file that contains your application. In the last line, we specify the port the server is listening to. When projects run within Cloud9 IDE, you must retrieve the port information using process.env.PORT.

Now, let's look at what the CoffeeScript file does.

It creates an HTTP server with a function that is called for each request. In the callback function, you create a response with a status code of 200 (indicating that the request was fulfilled successfully) and the message "Hello World". You use 'module.exports' to enable the server.js file to use the code in the CoffeeScript file.

Next, run the server.js file and open the URL indicated in the console:

The result is:

To stop your application, go back to the editor and click on the stop button (next to the run button).

Congratulations! You have just written and run a CoffeeScript application in Cloud9 IDE!

Comments

Benekastah

Is there a way to access the `coffee` command or the `cake` command? I require coffeescript's `cake` command line utility for building my project before it runs. It would also be nice to access coffeescript's repl.

December 1, 2011, 03:51

Drew Gilliam

This is probably a nube question, but how do I add another .coffee file and run it? for example I want to add another 'page' to my app called Start.coffee, how would I get it to run on the server shown here?

February 6, 2012, 05:32

Martin Keefe

I don't want to write a server in node/coffeescript but C9 seems to assume that. How can I set it to run/debug command line programs written in java/coffee -script?