Chapter 12. Modules and builds

 

This chapter covers

  • Modular applications with the Node.js module system
  • Automated builds
  • How to make modules work in a web browser
  • Releasing your modular application to the world

It’s unlikely that you’ll only ever write programs that are contained entirely in a single file. Instead, a typical application consists of many files, often written by many people, and, as a result, one big file won’t cut it. Breaking a program into many files makes each file easier to manage but also means you need some way to manage multiple files. Together, the files make up your program.

Individually, the part of the program contained in a single file is called a module. For example, you’re by now very familiar with fs, the filesystem module:

fs = require 'fs'

What you’re not yet familiar with is creating your own modules. That’s what you’ll learn in this chapter: how to create and use server-side modules for Node.js, how to build those modules into a complete application using Cake, how to run your tests against that built application, and how to use the same approach to modules in a web browser. Finally, you’ll learn how to deploy your program for the world to see. First up, modules.

12.1. Server-side modules (on Node.js)

JavaScript doesn’t have modules. To clarify: the JavaScript language doesn’t define a standard module system. The modules that you’ve used so far in your Node.js-based programs have been Node.js modules.

12.2. Build automation with Cake

12.3. Client-side modules (in a web browser)

12.4. Application deployment

12.5. The final Cakefile

12.6. Summary

sitemap