I am trying my hand at learning node.js using coffeescript but am having trouble wrapping my head around the flow.
My first task is to parse a csv file and add the parsed records to mongodb. Here is what I have thus far:
https://gist.github.com/1953474
I used a simple counter var that the addRule function increments on invocation and decrements at the end of the callback, checking to see if it was the last to finish so exit can be called. I think this is correct form but if there is a more proper way I am open to suggestion.
The real problem I am having is that nothing gets parsed or added to the database. Initially I realized I wasn’t waiting for the connection to be established but now I am stumped. I’m wondering if I’ve just missed some detail regarding how I should be working with mongoose…
Ideas?
Your counter specifically has two bugs.
Your not calling exit if the number of records is zero.
And your decrementing after rather then before.
n_out--returnsn_out,--n_outreturnsn_out - 1Your other mistake is using CoffeeScript, you’ll regret that.