如何解决Nodejs:错误:ENOENT:没有这样的文件或目录

时间:2022-12-14 23:19:47

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.

我有一个Nodejs Web应用程序当前正在服务器上成功运行。现在我正在尝试在我的开发服务器上设置本地副本。

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

我目前有Nodejs,NPM和Mongo安装就像我在生产服务器中安装的那样但是当我尝试启动节点服务器时出现以下错误

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$

3 个解决方案

#1


12  

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.

您的应用程序希望在/home/embah/node/nodeapp/config/config.json中找到一个文件,但该文件不存在(这是ENOENT的含义)。因此,您需要创建预期的目录结构,或者配置您的应用程序,使其在config.json的正确目录中查找。

#2


1  

I also had this issue because I had another console window open that was running the app and I was attempting to re-run yarn start in another console window.

我也遇到了这个问题,因为我打开了另一个运行应用程序的控制台窗口,我试图在另一个控制台窗口中重新启动纱线启动。

The first yarn executing prevented the second from writing. So I just killed the first process and it worked

第一根纱线阻止第二根纱线写入。所以我刚刚杀死了第一个进程并且它有效

#3


1  

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 :)

我不知道,但它可能会帮到某人:)

#1


12  

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.

您的应用程序希望在/home/embah/node/nodeapp/config/config.json中找到一个文件,但该文件不存在(这是ENOENT的含义)。因此,您需要创建预期的目录结构,或者配置您的应用程序,使其在config.json的正确目录中查找。

#2


1  

I also had this issue because I had another console window open that was running the app and I was attempting to re-run yarn start in another console window.

我也遇到了这个问题,因为我打开了另一个运行应用程序的控制台窗口,我试图在另一个控制台窗口中重新启动纱线启动。

The first yarn executing prevented the second from writing. So I just killed the first process and it worked

第一根纱线阻止第二根纱线写入。所以我刚刚杀死了第一个进程并且它有效

#3


1  

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 :)

我不知道,但它可能会帮到某人:)