I finally completed the conversion of one of my projects to using Node.JS, but now I have problems maintaining my application on the server: / The problem is that if I close the Node putty session, it just stops.
I searched a lot for this problem, and it seems like creating an upstart script and using the Forever module is the way to go.
I started googling and created this upstart script:
#!upstart description "Loner NodeJS app launcher" author " me@me.com " start on startup stop on shutdown script export HOME="/root" exec sudo node /home/jjmpsp/server.js >> /home/jjmpsp/server.sys.log 2>&1 end script
Then I launched the start app on the server last night, and the server stayed up when I closed the putty session. Things are good.
However, I came this morning and found that the Node application stopped, so I checked the server.sys.log file to see what was happening. The application seems to be working fine until it comes across this exception:
debug: client authorized info: handshake authorized fziLHZA3Vo9i55eubvOq events.js:48 throw arguments[1]; // Unhandled 'error' event ^ Error: Connection lost: The server closed the connection. at Protocol.end (/home/jjmpsp/node_modules/mysql/lib/protocol/Protocol.js:73:13) at Socket.onend (stream.js:80:10) at Socket.emit (events.js:88:20) at TCP.onread (net.js:348:51)
Today I googling even more and found that Forever will actually restart the NodeJS application if it unexpectedly exits. I tried installing the module with npm install forever , but I get this huge list of errors:
jjmpsp@alex :~$ npm install forever npm ERR! error installing forever@0.9.2 Error: No compatible version found: node-fork@ '>=0.4.0- <0.5.0-' npm ERR! error installing forever@0.9.2 No valid targets found. npm ERR! error installing forever@0.9.2 Perhaps not compatible with your version of node? npm ERR! error installing forever@0.9.2 at installTargetsError (/usr/local/lib/node_modules/npm/lib/cache.js:424:10) npm ERR! error installing forever@0.9.2 at /usr/local/lib/node_modules/npm/lib/cache.js:406:17 npm ERR! error installing forever@0.9.2 at saved (/usr/local/lib/node_modules/npm/lib/utils/npm-registry-client/get.js:136:7) npm ERR! error installing forever@0.9.2 at Object.cb [as oncomplete] (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:36:9) npm ERR! Error: No compatible version found: node-fork@ '>=0.4.0- <0.5.0-' npm ERR! No valid targets found. npm ERR! Perhaps not compatible with your version of node? npm ERR! at installTargetsError (/usr/local/lib/node_modules/npm/lib/cache.js:424:10) npm ERR! at /usr/local/lib/node_modules/npm/lib/cache.js:406:17 npm ERR! at saved (/usr/local/lib/node_modules/npm/lib/utils/npm-registry-client/get.js:136:7) npm ERR! at Object.cb [as oncomplete] (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:36:9) npm ERR! Report this *entire* log at: npm ERR! <http://github.com/isaacs/npm/issues> npm ERR! or email it to: npm ERR! < npm-@googlegroups.com > npm ERR! npm ERR! System Linux 3.8.4-x86_64-linode31 npm ERR! command "node" "/usr/local/bin/npm" "install" "forever" npm ERR! cwd /home/jjmpsp npm ERR! node -v v0.5.11-pre npm ERR! npm -v 1.0.106 npm ERR! Error: EACCESS, Permission denied 'npm-debug.log' npm ERR! Report this *entire* log at: npm ERR! <http://github.com/isaacs/npm/issues> npm ERR! or email it to: npm ERR! < npm-@googlegroups.com > npm ERR! npm ERR! System Linux 3.8.4-x86_64-linode31 npm ERR! command "node" "/usr/local/bin/npm" "install" "forever" npm ERR! cwd /home/jjmpsp npm ERR! node -v v0.5.11-pre npm ERR! npm -v 1.0.106 npm ERR! path npm-debug.log npm ERR! code EACCESS npm ERR! npm ERR! Additional logging details can be found in: npm ERR! /home/jjmpsp/npm-debug.log npm not ok
What steps should I take to fix this? I have absolutely no ideas. I was looking for all kinds of technical details, and I just don't get anything.
Any help is appreciated :)