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
  • PrintPrint
Share this Page URL
Help

10. Pro HTML5 Application Hacks with Nod... > Hack 84. Build a Custom Module to Ha...

Hack 84. Build a Custom Module to Handle Routing

Modularize the handling of requests made to your application within your own custom module.

In our main app.js file, we will make a few changes. First, our generator already created a new module that will isolate all our routing logic.

For the sake of demonstration, and in case you have the need to use static HTML files, we will disable the layout engine and configure Express to serve static HTML files from the /public directory. We will also turn off layout support.

Here is the app.js file:

var express = require('express')
 , routes = require('./routes');

var app = module.exports = express.createServer();

app.configure(function(){

 // disable layout
 app.set("view options"

  

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


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint