Skip to content

Step by step

Jesus Ruiz edited this page Aug 13, 2013 · 42 revisions

Step by step guide to get durable.js up and running, from local evaluation to cloud deploy. Simple is good.

MongoDb install

durable.js relies on MongoDb version 2.4. I have tested the 64 bit version for windows and mac. To get the database started follow the simple steps:

  1. Download MongoDB for Windows or MongoDB for Mac.
  2. Extract the zip\tgz package into a directory (for example, c:\mongo).
  3. Start a command prompt in admin mode in Windows or the terminal in Mac.
  4. Goto mongoDb bin directory (c:\mongo\bin) and create a /data/db directory: mkdir /data/db.
  5. From the mongoDb bin directory run the command mongod.exe in Windows, ./mongod in Mac.
  6. Congratulations! Your database is now up and running.

For more information go to: http://www.mongodb.org/downloads.

Node.js install

durable.js uses Node.js version 0.10.15. Getting node.js installed is very simple:

  1. Download Node.js for Windows or Node.js for Mac.
  2. Run the installer, don't fight it, just follow the instructions.
  3. The installer will set all the necessary environment variables, so you are ready to go.

For more information go to: http://nodejs.org/download.

First program

Now that your database and web server are ready, let's write our first program:

  1. Open a command prompt in admin mode in Windows or the terminal in Mac.
  2. Create a directory for your app: mkdir /firstapp.
  3. In the new directory npm install durable (this will download durable.js and its dependencies)
  4. In that same directory create a test.js file using your favorite editor.
  5. Type or copy and save the following code:
var d = require('durable');  
d.run({  
    sequence: d.receive({ content: 'first' })  
    .continueWith(function (s) { s.firstContinue = true; })  
    .checkpoint('first')
    .receive({ content: 'second' })
    .continueWith(function (s) { s.secondContinue = true; })  
    .checkpoint('second')
});  
  1. In the command prompt or terminal type node test.js.
  2. Open the web browser and go to: http://localhost:5000/sequence/1/admin.html. The UI you see should be similar to this.
  3. Type the message definition in the textbox at the bottom and click the 'Post Message' button.
{ "id":1, "content":"first" }  

Cloud deploy

I describe the steps I followed to host durable.js in the cloud. I was able to try all the functionality using free offerings. I found the services intuitive and easy to use. I did not run into any major issues. Of course when it comes to 24x7 production deployment the evaluation criteria is very different. So please feel free to choose the services that you see fit.

  1. Sign up for a Heroku account
  2. Sign up for a github account
  3. Sign up for a MongoHQ account
  4. Install git
  5. Install heroku toolbelt
  6. Create a git repository
  7. Write the package.json manifest
{
    "name": "test",
    "version": "0.0.1",
    "dependencies": {
        "durable": "0.0.1"
    },
    "engines": {
        "node": "0.8.x",
        "npm": "1.1.x"
    }
}
  1. Write the procfile
web: node test.js  
  1. Pass DB connection and port to durable.js
var d = require('durable');  
d.run({  
    sequence: d.receive({ content: 'first' })  
    .continueWith(function (s) { s.firstContinue = true; })  
    .checkpoint('first')
    .receive({ content: 'second' })
    .continueWith(function (s) { s.secondContinue = true; })  
    .checkpoint('second')
}, 'mongodb:(your connection string)', process.env.PORT);
  1. Push to git repository
  2. Push to Heroku
  3. Start dynos
Clone this wiki locally