Nodejs nohup dieing without an exception
http, javascript, node.js, nohup
Solution
I faced a similar problem ( but don't know whether there is a common reason )
Solution :
- ssh to the server
- run `nohup node app.js &` as normal
- Ctrl+c to exit from nohup
- Gracefully exit from ssh i.e via exit command not by just closing the terminal.
Last point is important I was not exiting from the ssh correctly hence it was getting killed.
Problem
I am writing my first NodeJS app but for some reason it seems to die unexpectedly after a short amount of time. I have no clue what would be causing it. The process runs fine, even works as expected, then for some reason it just stops. The nohup log does not show an error or any feedback. I have tried running this in debug mode but its the same, no information. The trace is no help. I run the process via nohup: ``` nohup node app.js & ``` Code: ``` var http = require('http'); var server = http.createServer().listen(8000); var io = require('socket.io').listen(server); var cookie_reader = require('cookie'); var querystring = require('querystring'); // Store the session cookie set by Django io.configure(function(){ io.set('authorization', function(data, accept){ if(data.headers.cookie){ data.cookie = cookie_reader.parse(data.headers.cookie); return accept(null, true); } return accept('error', false); }); io.set('log level', 1); }); io.sockets.on('connection', function (socket) { socket.on('shoutbox_send', function(message){ values = querystring.stringify({ comment: message, sessionid: socket.handshake.cookie['sessionid'], }); try { var options = { host: 'www.example.com', port: 80, path: '/shoutbox/node_api', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': values.length } }; var req = http.get(options, function(res){ res.setEncoding('utf8'); res.on('data', function(message){ socket.emit('shoutbox_receive', message); socket.broadcast.emit('shoutbox_receive', message); }); }); req.write(values); req.end(); } catch (err) { console.log(err); socket.emit('shoutbox_receive', err); } }); }); ``` Thanks in advance,