Skip to content

Step by step

jruizgit edited this page Jul 30, 2013 · 42 revisions

Step by step

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') });

...
6. In the command prompt or terminal type node test.js.
7. Open the web browser and go to: http://localhost:5000/sequence/1/admin.html. The UI you see should be similar to this.
8. 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 found the services nice and convenient, plus I was able to try all the functionality using the free services. 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 package.json

    { "name": "test", "version": "0.0.1", "dependencies": { "durable": "0.0.1" }, "engines": { "node": "0.8.x", "npm": "1.1.x" } }
    ...

  8. procfile

    web: node test.js
    ...

  9. Passing DB connection and port to durable.js

  10. git push

  11. heroku push

  12. dyno start

Clone this wiki locally