In beginner tutorials, Node’s non-blocking nature is usually demonstrated by showing a blocking example (using a return statement) and the non-blocking Node example (using callbacks). For an example, see here.
Should I take it as a “smell” that using return creates blocking code in my Node app, and find a way to redo it using callbacks?
TL;DR: if code may take a “long” time, it may be cleaner/more efficient to handle it with a callback.
It’s not about return/not-return, it’s about what the code actually does.
The example function doesn’t block because there’s a return, it blocks because
db.querytakes an arbitrary amount of time. If you want to do other things during that time, return right away, and do the result processing in the callback.Whether or not you should depends on what’s actually going on, what else may be affected by, or depend on, the data passed to the callback (or returned), and so on.