Skip to content

Deploying a Backbone.js App

Backbone.js is a lightweight JavaScript framework that provides structure to web applications by offering models, collections, and views. It is ideal for building single-page applications (SPAs) and is known for its simplicity, flexibility, and ease of integration with other libraries.

This guide explains how to deploy a Backbone.js application to Klutch.sh, both with and without a Dockerfile. It covers installation, sample code, and deployment steps.

Prerequisites

  • Node.js & npm installed (Download)
  • Git and GitHub account
  • Klutch.sh account

Getting Started: Create a Backbone.js App

  1. Create a new project directory:
    Terminal window
    mkdir my-backbone-app
    cd my-backbone-app
    npm init -y
    npm install backbone underscore jquery
  2. Create an index.html file with the following sample code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Backbone.js on Klutch.sh</title>
    <script src="node_modules/jquery/dist/jquery.min.js"></script>
    <script src="node_modules/underscore/underscore-min.js"></script>
    <script src="node_modules/backbone/backbone-min.js"></script>
    </head>
    <body>
    <div id="app"></div>
    <script>
    var HelloView = Backbone.View.extend({
    el: '#app',
    render: function() {
    this.$el.html('<h1>Hello from Backbone.js on Klutch.sh!</h1>');
    }
    });
    var view = new HelloView();
    view.render();
    </script>
    </body>
    </html>

Deploying Without a Dockerfile

Backbone.js apps are static sites. Klutch.sh can deploy static sites directly.

  1. Push your Backbone.js app (including index.html and dependencies) to a GitHub repository.
  2. Log in to Klutch.sh.
  3. Create a new project.
  4. Create a new app:
    • Select your Backbone.js GitHub repository and branch
    • Choose “Static Site” as the app type
    • Set build command: (leave blank if not using a build tool)
    • Set output directory: the directory containing index.html (usually the root)
    • Configure region, compute, and environment variables as needed
  5. Click “Create” to deploy. Klutch.sh will serve your static Backbone.js app.

Deploying With a Dockerfile

If you need custom server logic or want to use a Dockerfile:

  1. Add a Dockerfile to your project root. Example:
    FROM nginx:alpine
    WORKDIR /usr/share/nginx/html
    COPY . .
    EXPOSE 80
    CMD ["nginx", "-g", "daemon off;"]
  2. Push your code (with Dockerfile) to GitHub.
  3. In Klutch.sh, create a new app and select the Dockerfile option when prompted.
  4. Set service details and environment variables as needed.
  5. Click “Create” to deploy. Klutch.sh will build your Docker image and serve your Backbone.js app via Nginx.

Resources


Deploying Backbone.js to Klutch.sh is simple and flexible. Use static site deployment for most cases, or Dockerfile for custom setups.