Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve Nodejs: Error: ENOENT: no such file or directory

I have a Nodejs web app currently running on a server successfully. Now I'm trying to setup a local copy on my Development server.

I currently have Nodejs, NPM and Mongo Installed just like what I have in production server however the error below occurs when I try to start node server

Whats could be causing this issue?

embah@devsertwo:~/node/nodeapp$ node app.js fs.js:640   return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);                  ^  Error: ENOENT: no such file or directory, open '/home/embah/node/nodeapp/config/c onfig.json'     at Error (native)     at Object.fs.openSync (fs.js:640:18)     at Object.fs.readFileSync (fs.js:508:33)     at Object.<anonymous> (/home/embah/node/nodeapp/config/config.js:4:28)     at Module._compile (module.js:570:32)     at Object.Module._extensions..js (module.js:579:10)     at Module.load (module.js:487:32)     at tryModuleLoad (module.js:446:12)     at Function.Module._load (module.js:438:3)     at Module.require (module.js:497:17)     at require (internal/module.js:20:19)     at Object.<anonymous> (/home/embah/node/glorby/app.js:13:16)     at Module._compile (module.js:570:32)     at Object.Module._extensions..js (module.js:579:10)     at Module.load (module.js:487:32)     at tryModuleLoad (module.js:446:12)     at Function.Module._load (module.js:438:3)     at Module.runMain (module.js:604:10)     at run (bootstrap_node.js:394:7)     at startup (bootstrap_node.js:149:9)     at bootstrap_node.js:509:3 embah@devsertwo:~/node/nodeapp$ 
like image 892
Emeka Mbah Avatar asked Apr 06 '17 16:04

Emeka Mbah


People also ask

How do I fix error Enoent No such file or directory?

To resolve the ENOENT warning message, you need to add a package. json file in the directory where you run the npm install command. And then run your npm install command again. This time, the warning message should not appear.

What does error code Enoent mean?

It's an abbreviation of Error NO ENTry (or Error NO ENTity), and can actually be used for more than files/directories. It's abbreviated because C compilers at the dawn of time didn't support more than 8 characters in symbols. Follow this answer to receive notifications. edited Jun 4, 2019 at 14:30. community wiki.


2 Answers

Your app is expecting to find a file at /home/embah/node/nodeapp/config/config.json but that file does not exist (which is what ENOENT means). So you either need to create the expected directory structure or else configure your application such that it looks in the correct directory for config.json.

like image 179
Trott Avatar answered Oct 05 '22 23:10

Trott


After going through so many links and threads and getting frustrated over and over again, I went to the basics and boom! it helped. I simply did:

npm install 

I don't know, but it might help someone :)

like image 24
olleh Avatar answered Oct 06 '22 01:10

olleh