About the current working directory change during coding for the promise topic: avoiding the common mistakes

When I am running the program by using “node app.js”, sometimes it gives CWD error. "The file or directory doesn’t exist. I close and reopen the page again, then the code can run normally.
I printed the working directory, and found they are different in the two cases. What’s the mechanism for this one? I no need to do anything, just close and reopen it again, the issue can be resolved. How the working directory got changed? thanks a lot.