Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS Error: node.js:810 var cwd = process.cwd();

Tags:

node.js

I'm new to nodeJS and also new to StackOverflow...

I'm starting to develop my first SPA, using RequireJS to compile my sources into a "dist" folder. I had NodeJS running a basic script to run my server:

var connect = require('connect'); connect.createServer(     connect.static(__dirname) ).listen(8080); 

Everything was working well, till I compile my src again. That replaced all the files served by my server, so I though I would restart Node. I Ctrl^C and from this moment, I can't get Node to start again. When I try to run:

olivier$ node server.js  

I get this error:

node.js:810     var cwd = process.cwd();                   ^ Error: ENOENT, no such file or directory     at Function.startup.resolveArgv0 (node.js:810:23)     at startup (node.js:58:13)     at node.js:901:3 

What's strange is that I get the same error just trying to start NodeJS, simply doing:

olivier$node 

Anyone has an idea of what I can do beside uninstalling Node and reinstalling it ?

like image 583
user2984480 Avatar asked Nov 12 '13 18:11

user2984480


2 Answers

I got this when trying to run the Node REPL from a directory I had already deleted (from another shell). Don't let this happen to you or you will be ashamed.

like image 190
fiatjaf Avatar answered Sep 28 '22 05:09

fiatjaf


Could it be that RequireJS is also recreating the directory that contains your server.js?

Try and see if this works:

$ cd $PWD; node server.js 

Although it seems useless to change the directory to the current directory, the rationale is that when a directory gets deleted while it's the current working directory of your shell, the shell is left in a dangling state because it's still 'attached' to the previously deleted directory. This also affects any processes that you start from that shell (like Node), and can yield confusing errors.

By executing cd $PWD, you make sure your shell gets 'reattached' to the newly created version of the directory, solving the dangling state.

like image 28
robertklep Avatar answered Sep 28 '22 03:09

robertklep