I'm author of node-x11, but your questions seems to be generic and not related to x11.
Example where you might want to detach from terminal is implementing xclip in js ( see this discussion )
Lots of possible solutions here tl;dr - if you don't want to detach it from outside with nohup
you can use module like daemon