Server-Side CoffeeScript

The CoffeeScript you’ve seen so far in this book is best described as client-side, CoffeeScript is designed as a solution to the various problems that web developers face, which usually means code working within the environment of the web browser. Although many of the facilities and features of CoffeeScript are designed to solve client-side problems, it’s not the whole story.

JavaScript has exploded as a server-side scripting language over the past few years, and the reason for this is a project called Node.js, or simply node. Taking a different approach to the technical architecture of a web server, node asks the JavaScript developer to write highly event-driven and function-oriented code.

It turns out that the event-driven style of coding required by node suits CoffeeScript down to the ground: all of the features that make CoffeeScript compelling in the client-side environment transfer directly to the server-side environment, and development of node-based servers is even more straightforward.

Putting Coffee in the server

Before delving too far into the details, I want to take a few moments to recap some of the long and glorious history of JavaScript, starting with the early days of Netscape . From the beginning, JavaScript was intended to be a server-side language and a client-side one, and one of the earliest versions of Netscape Enterprise Server included support for it. By 1996, Microsoft also had included support for the language in its ...

Get Smashing CoffeeScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.