Piotras: have a look at node::AtExit()