brikis98 / node-backbone-skeleton

A skeleton project for creating applications that use node.js server-side, backbone.js client-side, underscore.js templates, CoffeeScript as a JS pre-processor and Compass/SASS as a CSS pre-processor..
84 stars 16 forks source link

Update

This project is from 2011 and is no longer maintained. It has been supersceded by the many node.js frameworks that are now available and tools like grunt.js and gulp.js.

Overview

This is project represents the skeleton of an application with node.js server-side and backbone.js client-side. All JavaScript is written using CoffeeScript, all CSS is written using Compass and SASS, all templates are written using underscore.js and all client-side JavaScript is packaged using Jammit. A utility class is provided that automatically recompiles & packages all of these pre-processor languages every time you hit save, so you can iterate quickly: make a code change, hit refresh.

node-backbone-skeleton is primarily for my own personal use and not a battle-tested, production-ready framework. However, I've found it useful for a few projects, so perhaps other developers will find it a handy starting point.

Getting Started

  1. gem install compass
  2. npm install glob
  3. gem install jammit
  4. npm install -g coffee-script
  5. Add the NODE_ENV=development to your environment variables (e.g. add export NODE_ENV=development to .bash_profile)
  6. Run with node server.js (or node-dev server.js to get "hot redeploy")
  7. Go to http://localhost:8003
  8. Make changes to the code and watch the CoffeeScript, SASS and templates get recompiled as soon as you hit save

Technologies

Directory structure

/util/watcher.coffee

This class is loaded by server.js at startup to watch the project using watch-tree and recompile and package files as necessary so that you can iterate quickly. The goal is to support "make a change, hit reload" style development even though this project uses a number of pre-processors that require "compilation". It works reasonably well already and as I improve, I'll likely break this off into its own Github/NPM project.

Sample usage:

var Watcher = require('./util/watcher').watcher;
var options = {
  compass: 'config/config.rb',
  verbose: true,
  templates: templates,
  package: 'config/jammit.yml',
  packageOut: 'public/js',
  paths: {
    'server.coffee':                    {type: 'coffee', out: '.'},
    'templates/**/*.html':              {type: 'template', out: 'compiled/templates', package: true},
    'views/**/*.coffee':                {type: 'coffee', out: 'compiled/views', package: true}     
  }
};
var watcher = new Watcher(options);
watcher.watch();

Executing the watch() function does the following: