add a callback

The default behaviour of terminating the process / stdin is really aggresive. 

It makes this file unusable as a module, so we moved the callback into the require.main block.

cc @sh1mmer @dfellis @kumikoda