How to close a Terminal window while executing a file with node.js without stopping the process?

When I execute a file with node.js (by typing "node example.js", maybe a http server), then, when I close the Terminal window (Mac OS X Lion), the process is stopped and doesn't answers on requests anymore. The same happens if I type "ctrl c" or "ctrl z". How can I close the Terminal without stopping the process, so my server continues answering on requests.

Use a combination of the nohup prefix command (to keep the process from being killed when the terminal closes) and the & suffix (to run the process in the background so it doesn't tie up the terminal): nohup node example.js &

You should also look into forever or similar tools that will also automatically restart the server if it crashes, and nodemon which will automatically restart it when you change the code.