Why won't this node.js script stay open in the terminal?

I'd like to know how to run this script without entering node script_name.js into the terminal. The prompt is displayed when I start the script from the terminal, but when I try to run the script as a program (from the file manager, not the command line), it simply opens and closes the terminal, without displaying a prompt.

#!/usr/local/bin/node

var prompt = require('prompt');

//var stuff = require("./stuff");

  prompt.start();

  prompt.get(['username', 'email'], function (err, result) {
    if (err) { return onErr(err); }
    console.log('Command-line input received:');
    console.log('  Username: ' + result.username);
    console.log('  Email: ' + result.email);
  });

  function onErr(err) {
    console.log(err);
    return 1;
  }

Here is the expected output (with input) for this program:

anderson@anderson-Ideapad-Z560:~/AeroFS/node.js examples$ node node_prompt_demo.js
prompt: username:  blah
prompt: email:  blah@example.com
Command-line input received:
  Username: blah
  Email: blah@example.com

This almost certainly has to do with the controlling tty. I'm guessing the file manager you're using doesn't give you a stdin that's attached to anything and it just exits without any input.

Your best bet would be to wrap this in a program that would give it a valid stdin. For example, on a Mac, I run the node script within Terminal.app so it always gets a valid stdin. Should be able to do something similar in XWindows. If you're not using a window manager, you could also try using "expect" and 'screen'. The combination of these should get you what you want.