Neolithic Programming Machine


    0.3.9 • Public • Published


    Backbone-Server creates a Server module which pulls together Backbone and Express to bring greater structure to your NodeJS applications.

    Backbone.Server can be accessed just like any other Backbone module:

    var Backbone = require('backbone-server'); // Note: Backbone-Server relies on the backbone npm package and is not required.
    // Current defaults for Backbone.Server
    var server = new Backbone.Server({
        'express'        : express.createServer(),   // The actual server handling everything
        'port'           : 8000,                     // The port the server will run on
        'public'         : 'public',                 // The directory for static content
        'routes'         : {},                       // For quick apps, basic routes you can configure upon instantiation
        'socketio'       : false,                    // If set to true, adds socketio support to the server
        'views'          : 'views',                  // The directory where views can be found
        'view engine'    : 'ejs'                     // The engine used to render views


    Once you have added a Server, add routes just as you would with Express:

    server.get('/post/:id', function(req, res) {
        var id =,
            article = articles.get(id);
        res.render('single', article);
    });'/post', function(req, res) {
    server.put('/post/:id', function(req, res) {
        var article = article.get(;
    server.delete('/post/:id', function(req, res) {

    Using functions:

    To enable functionality, set the socketio attribute to true upon creation of your new Backbone.Server object:

    var server = new Backbone.Server(
        'socketio'     : true          // If set to true, Backbone.Server will enable functionality

    This will create an instance of at the io attribute of your new server object ( You can now add standard events using the bind and receive methods, like so:

    // Socket.IO Functions
    server.bind('connection', function() {
        var Article = new Backbone.Model(),
            Articles = new Backbone.Collection({
                model: Article
            // code to add records to Articles data
        server.send('models', Articles.toJSON());

    In your clientside application, you can receive commands from the server like so (note that backbone-server automatically provides a route to load Underscore and Backbone):

    <script src="/backbone-server/backbone.js" type="text/javascript"></script>
    <script src="/" type="text/javascript"></script>
        var socket = io.connect('http://localhost');
        var Article = Backbone.Model.extend();
        var Articles = Backbone.Collection.extend({
            model: Article,
            initialize: function() {
                // Bind an event to notify when an article has been added to the server
                this.bind('add', function(article) {
                    console.log("Article added!");
        var articles = new Articles();
        socket.on('models', function(data) {
            articles.add(d);   // queues the collection event ('articles added!');

    To summarize, in the example above, we've created a Backbone.Server which will push down server side models upon connection, and add them to the client scripts Articles collection.

    Starting the Server:

    Once you have created a server starting it is easy:


    Don't see something here you like from Express or

    Target Express directly:

    // == Express

    Target directly:

    // ==




    npm i backbone-server

    DownloadsWeekly Downloads






    Last publish


    • nhunzaker