While booting my Node.js app, I want to make a couple of synchronous calls to the PostgreSQL database to check some things before continuing the control flow. How can I achieve this using the node-postgres package?
Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up
Join them; it only takes a minute:
The only way to synchronize calls is to nest them in callbacks:
This can be a pain, and would be trivial in some other languages, but it is the nature of the beast. |
|||||||||
|
I think this would be applicable. |
|||
|
Given that the call is inherently asynchronous, you'll need to manage it either via callbacks (the defacto Node style), async or via promises (Q, when.js, Bluebird, etc...) Please note that wrt to the accepted answer, callbacks are not the only way to do this. |
|||
|
brianc (author of node-postgres) commented here, that
Hope this helps... |
|||
|