I have 2 function that i'm running asynchronously, i'd like to write them 
using the waterfalll model, the thing is that i don't know how.. Here is my 
code :

var fs = require('fs');function updateJson(ticker, value) {
    //var stocksJson = JSON.parse(fs.readFileSync("stocktest.json"));
    fs.readFile('stocktest.json', function(error, file) {
        var stocksJson =  JSON.parse(file);



        if (stocksJson[ticker]!=null) {
            console.log(ticker+" price : " + stocksJson[ticker].price);
            console.log("changing the value...")
            stocksJson[ticker].price =  value;
            console.log("Price after the change has been made -- " + 
stocksJson[ticker].price);
            console.log("printing the the Json.stringify")
            console.log(JSON.stringify(stocksJson, null, 4));
             fs.writeFile('stocktest.json',JSON.stringify(stocksJson, null, 4) 
, function(err) {  
                            if(!err) {
                                console.log("File successfully written");
                            }
                            if (err) {
                                console.error(err);
                            }

                       }); //end of writeFile
        }
        else {
            console.log(ticker + " doesn't exist on the json");
        }
    });} // end of updaJson 

Any idea how can i write it using the waterfall so i'll be able to control 
this, Please write me some examples because i'm new to node.js

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/c22eb8df-0efa-4db2-80b7-fcf80b9239dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to