HTML and CSS Reference
In-Depth Information
Listing 19-1: The package.json file
"name": "platformer-editor"
, "version": "0.0.1"
, "private": true
, "dependencies": {
"express": "2.5.8"
, "jade": ">= 0.0.1"
, "underscore": "1.3.3"
This application has three dependencies, your good friend underscore.js; a Node.js application framework
called Express; and its dependency, jade.
Setting Up Node to Serve Static Assets
Node.js provides a minimal baseline of functionality for processing web requests. To get it to do something
such as serve static files, you need to pull in a module. There are a number of different modules you could use
whose only purpose is to serve static files, including node-static and node-paperboy , but because this
app is going to do more than just serve files, it makes sense to pull in a more full-featured framework that can
handle static files in addition to other tasks. The framework you use for this is a Node module called Express: .
Express provides a number of different features, including views, caching, routing, sessions, and static files.
This chapter uses only a small subset of Express's features, but it still makes your life easier than trying to use
Node.js without support. You'll install Express via npm , so don't worry about downloading it.
Create a file called app.js in the editor directory for your app that you just created and fill it with the
contents of Listing 19-2 , which is a basic boilerplate Express application.
Listing 19-2: Express boilerplate application
var express = require('express'),
fs = require('fs'),
_ = require('underscore');
var app = module.exports = express.createServer();
// Configuration
app.use(express.static(__dirname + '/public'));
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true
app.configure('production', function(){
Search WWH ::

Custom Search