Skip to content


Subversion checkout URL

You can clone with
Download ZIP
JavaScript Shell
Tree: cf5af9a5cd

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.

Sharing RequireJS modules

This example shows how to reuse code between the client and server. A typical use case would be to use the same validation logic for your models on both sides.

Feel free to use it as a basic template for your applications.

Project structure

This backbone application is divided into a couple of AMD modules. A special shared module is used inside the node.js server. It is possible to test all modules using mocha and expect.js. (Examples included)

The Backbone app is inside the 'client' folder. The server is inside the 'server' folder (obviously...). Any module which should be shared between client and server is in the 'shared' folder and has to start with the amdefine wrapper. The minified client app is in the 'client-build' folder. This folder gets deleted on every build.


The following steps were tested with the following environment:

MacOS 10.7.3
Node.js 0.6.14
npm 1.1.16

Check out this git repository:

$ git clone

Remove git history if you want to use this example as a template for your project:

$ cd backbone-requirejs-node-boilerplate
$ rm -rf .git

Install node.js if you haven't already:

Install npm (should already be installed if you are using the latest node setup):

$ curl | sh

Install node packages for the node.js server:

$ npm install .

Start the development server and navigate to 'http://localhost:8000':

$ node server/server.js

Or use nodemon for watching your server files and automatically restart the server:

$ npm install -g nodemon
$ nodemon server/server.js

Run unittests:

$ make test

Build (concatenate and minify) everything using r.js:

$ cd bin
$ ./

Start production environment (node will use the client-build folder with the minifed client app):

$ NODE_ENV=production node server/server.js


  • Provide a coffeescript version
  • Add strict mode: "use strict";


MIT license (of course).

Something went wrong with that request. Please try again.