my nodejs script is not exiting on its own after successful execution

You have to tell it when you're done, by calling

process.exit();

More specifically, you'll want to call this in the callback from async.waterfall() (the second argument to that function). At that point, all your asynchronous code has executed, and your script should be ready to exit.

EDIT: As pointed out by @Aaron below, this likely has to do with something like a database connection being active, and not allowing the node process to end.


I just went through this issue.

The problem with just using process.exit() is that the program I am working on was creating handles, but never destroying them.

It was processing a directory and putting data into orientdb.

so some of the things that I have come to learn is that database connections need to be closed before getting rid of the reference. And that process.exit() does not solve all cases.

When my project processed 2,000 files. It would get down to about 500 left, and the extra handles would have filled up the available working memory. Which means it would not be able to continue. Therefore never reaching the process.exit at the end.

On the other hand, if you close the items that are requesting the app to stay open, you can solve the problem at its source.

The two "Undocumented Functions" that I was able to use, were

process._getActiveHandles();
process._getActiveRequests();

I am not sure what other functions will help with debugging these types of issues, but these ones were amazing.

They return an array, and you can determine a lot about what is going on in your process by using these methods.

I just hope that helps anyone else stumbling across this post.