Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: EBADF, bad file descriptor when running node using nohup of forever

I have a problem with node.js running a small web server serving files from the file system. When starting it with node server.js it works like a charm but when starting it with nohup or forever node.js can't find the files.

like image 775
javabeangrinder Avatar asked May 17 '13 07:05

javabeangrinder


3 Answers

This works for me:

nohup node server.js </dev/null
like image 79
forzagreen Avatar answered Nov 05 '22 01:11

forzagreen


Another solution here is to run the command in a subshell using parentheses. (nohup node index.js)

like image 4
Jk Jensen Avatar answered Nov 04 '22 23:11

Jk Jensen


It turned out to be the file path of the file that was the problem. When running the server using node the working directory is the same as the server.js file thus node.js manages to find the file.

When starting whilst using nohup or just starting with forever the working directory doesn't seem to be the same as server.js.

I solved this by prepending the global variable __dirname to the filename.

like image 2
javabeangrinder Avatar answered Nov 04 '22 23:11

javabeangrinder