forever: var cwd = process.cwd(); Error: No such file or directory

We are seeing this following behavior often with forever.

When starting an app, the following is logged to the error log over and over again:

 node.js:289
      var cwd = process.cwd();
                  ^
 Error: No such file or directory
      at Function.resolveArgv0 (node.js:289:23)
      at startup (node.js:43:13)
      at node.js:448:3

We are running node 4.1.2 and forever 0.7.5. Forever is instantiated like:

    //Setup spawn child
    var child = new(forever.Monitor)(torqueObject.start, {
        silent: true,
        forever: true,
        watch: false,
        sourceDir: "/nodesocket/gears/" + gear,
        outFile: "/nodesocket/gears/" + gear + "/logs/output.log",
        errFile: "/nodesocket/gears/" + gear + "/logs/error.log",
        logFile: "/nodesocket/gears/" + gear + "/logs/forever.log",
        pidFile: "/etc/nodesocket/lever/pids",
        options: torqueObject.parameters,
        minUptime: 2000,
        spinSleepTime: 1000,
        killTree: true,
        env: torqueObject.env
    });

    //Acutally spawn child
    child.start();

Obviously its trying to get the current working directory, but failing. Any idea what specific code in forever is calling process.cwd().

About this issue

  • Original URL
  • State: closed
  • Created 13 years ago
  • Comments: 29 (4 by maintainers)

Most upvoted comments

I don’t know if this helps but I ran into this error, then I closed all my terminals and I ran my command “sudo npm cache clean -f” and “sudo npm install -g n” and voila: no more process.cwd problems.

I have an inkling that opened terminals in Vim and in npm folders might be the cause of the error.

Usually this indicates you are attempting to run a node script in a directory that doesn’t exist on the system.

I’d suggest trying to add some guards before the new forever.Monitor call to ensure that your sourceDir, outFile, errFile, etc, exist.

in iTerm right click in the terminal window and choose ‘restart’. Thanks @geoyws

@geoyws Great, that worked for me, thanks. (All I had to do was cd to no directory)

tanks @mxdi9i7 . restarting terminal solved the issue

@geoyws Super Thanks 😃 I didn’t run the commands but closed terminal and opened it again. works perfect. 😃

@whomever-might-have-similar-issue I’m testing it on CentOS Linux node version. I didn’t have this problem before but now for the other server, I have this issue. Seems like system couldn’t find the npm path correctly if you don’t restart you putty or whatever for the other users.

  1. installed npm linux version and works perfect (node -v, npm -v)
  2. logout, login with other user but only node -v works, and get this error when run ‘npm -v’ command
  3. restarted putty.
  4. works perfect.

For anyone still having this issue in 2019, if it is inside a docker container, removing the container and forcing a recreation fixes thi issue.

Just restart terminal

If you want you can run sudo npm cache clean -f but not necessary.

My problem was solved by closing the terminal and navigate into the project root again to start the app. I think my issue was caused by checking out a branch that that doesn’t have the project directory in it to run the app.