Running a server with CoffeeScript
In Chapter 10, Using CoffeeScript in More Places, one of the systems we looked at was a Node server using Express. At that time, we left the server code in JavaScript and focused on using connect-assets to compile our client-side CoffeeScript into JavaScript. Now, we're going to use that Express application again, but we'll be working on the server-side code. And you guessed it—we'll be writing CoffeeScript.
Tip
Our package.json
already includes coffee-script
as a dependency, since we're using it for asset compilation. If it didn't, though, we would need to add coffee-script
to the devDependencies
to make sure our development tools have access to the CoffeeScript compiler.
We'll start with the Express server JavaScript code from Chapter 10, Using CoffeeScript in More Places. We could convert it to CoffeeScript manually, but there's a neat utility that we can use to convert JavaScript to CoffeeScript automatically. It's named, appropriately, js2coffee
, and...