Skip to content

Step by step

jruizgit edited this page Jul 29, 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

  1. Install git

  2. Install heroku toolbelt

  3. Create a git repository

  4. Write package.json

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

... 5. procfile

web: node test.js
  1. git push
  2. heroku push
  3. dyno start
Clone this wiki locally