Your get function returns undefined because you don't specify a return value. You specify a return value for your callback function, but your outer function doesn't know or care about that. If you want the behavior you expect, you need to pass in a callback to your get function to have access to the rows variable.