There are tons of comments here. First of all, for the operation of your sample server, handleRequest must be defined before use.
1- What you really want, which impedes the exit process, can be handled by handling uncaughtException ( documentation ) event:
var handleRequest = function(req, res) { res.writeHead(200); res1.end('Hello, World!\n'); }; var server = require('http').createServer(handleRequest); process.on('uncaughtException', function(ex) {
2- I would suggest using try {} catch (e) {} in your code, for example:
var handleRequest = function(req, res) { try { res.writeHead(200); res1.end('Hello, World!\n'); } catch(e) { res.writeHead(200); res.end('Boo'); } };
3- I think the example was just an example, not the actual code, this is a parsing error that can be prevented. I mention this since you MUST have parsing errors in catch Exception handlers.
4. Note that the node process will be replaced in the future domain
5- I would rather use a framework like express than doing this.
6- Recommended lecture: fooobar.com/questions/13145 / ...
source share