Skip to content
Advertisement

Terminal hanging while running an asynchronous JS script to populate a Mongoose DB

I’m working on a personal project and am trying to understand the process logic that keeps my Node JS process from terminating after calling populateTransactions().

I think its because I need to close the DB (I’m not entirely clear on why), but when I do, the process terminates but the save() function of the model doesn’t complete and the DB isn’t written correctly.

When I let the script hang, eventually, it populates the DB correctly, but doesn’t terminate.

JavaScript

Advertisement

Answer

So I figured out that the issue was originating from

JavaScript

not following the await behavior. It turned out that the save() function doesn’t return a promise if you pass a callback as a parameter, so I refactored the code so that it didn’t use a callback and it worked as normal.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement