Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

9. Intro to Node.js > Building a CoffeeScript Server

Building a CoffeeScript Server

Let’s build something that might be useful to us—an app server. Our spec for our server is going to be pretty simple. It’s going to look at the requests that come in and then do one of three things. If the file requested is a JavaScript file, it is going to look in the src directory for the corresponding CoffeeScript file, compile that file into JavaScript, and return that. If the requested file or path is not JavaScript, the server will find the corresponding file in the public directory and serve up that file. Finally, if there is no matching CoffeeScript in the src directory or no matching file in the public directory, the server should respond with a simple 404 page.

We know what we want to build, but before we build it, you should know that the code we will build in this section is going to get a bit big, and we’re going to be iterating over it. Because of this, I am not going to show you the compiled JavaScript until we have finished writing our server. Trust me, you will thank me for it. Now, let’s get building.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial