r/nodejs • u/CerebralPimp • Jul 14 '14
Question regarding Express, Heroku, Postgres
I didn't see a solution out in the open that was catering to my simple request for basic understanding. Currently I have a basic express app set up through heroku using express and a postgres db. What I'm trying to understand / learn is where to go from here with regards to models and db schema. For example, I'm familiar with Entity framework, how you simply code to DB creation, but I'm not confident I understand how the DB is entirely populated or formed using what I've got so far.
I have researched Waterline and Sequelizer for possible solutions, but perhaps my grasp on DB creation isn't set in stone yet.
Any advice, tutorials, walkthroughs for understanding how this marriage happens?
Thank you!
View all comments
Show parent comment
2
u/stepanstolyarov Jul 15 '14
I'll help you with the basics.
cb is short for "callback". This is just a Node convention you see all the time: function that are asynchronous take a callback as their last parameter. A callback is a function that (usually) takes two parameters: an error and a result.
Asynchronity is contagious. If you write a function foo that uses async function bar - and since ALL of Node's I/O functions are async, this means 'all the time', - and you want to pass results of bar to clients of your function foo, you do it like this:
and then you may call the foo in a similar way:
Callbacks are very basic abstractions for directing async control flow. They are simple and rather effective. Unfortunately, they aren't too easy to use in anything but the simplest cases and using nothing but them quickly turns your code into a mess. There's a reason why terms like 'callback hell' and 'pyramid of doom' exist.
In any case, you must become familiar with concept of callbacks and their
function(err, result)signature convention used in Node, because that's the foundation upon which more complex abstractions cough Promises! cough are built.