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

I have a problem with node.js, which runs a small web server serving files from the file system. When launched from node server.js it works like a charm, but when launched from nohup or forever, node.js cannot find the files.

+6
source share
3 answers

This turned out to be the file path of the file that was the problem. When starting the server using node, the working directory is the same as the server.js file, so node.js manages to find the file.

When started using nohup or just starting forever, the working directory does not look the same as server.js.

I solved this by adding the __dirname global variable to the file name.

+1
source

This works for me:

 nohup node server.js </dev/null 
+5
source

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

+2
source

Source: https://habr.com/ru/post/945237/


All Articles