75
votes

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$
17
It's complaining about a missing file. Do you have "/home/embah/node/nodeapp/config/c onfig.json" in the correct location in your system?TeaCoder

17 Answers

63
votes

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.

39
votes

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

13
votes

92% additional asset processing scripts-webpack-plugin× 「wdm」: Error: ENOENT: no such file or directory, open....==> if anyone faced to such error, you should do followings: 1) you should check the if the file path is correct in angular.json file.

 "scripts": [
          "node_modules/jquery/dist/jquery.min.js",
          "node_modules/bootstrap/dist/js/bootstrap.js"
        ],

2) you should press crtl+c and re run the project.

10
votes

@olleh answer worked because npm install will create a node_modules directory in the current path where it is executed. So, while using the file server system module, the below declaration locate files from the top level directory of node_modules.

const fs = require('fs')
7
votes

In my case the issue was caused by using a file path starting at the directory where the script was executing rather than at the root of the project.

My directory stucture was like this: projectfolder/ ├── package.json ├── scriptFolder/ │ ├── myScript.js

And I was calling fs.createReadStream('users.csv') instead of the correct fs.createReadStream('scriptFolder/users.csv')

4
votes

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

2
votes

If there is no layout folder.Just use like this to your routing:

app.get('/', (req, res) => {
    res.render('something', { layout: false });
})

Here change something with your folder name and Hope it will fix your error.

2
votes

I was facing this issue with ng-package.json file, while creating a plugin. I found out I was providing the wrong path in angular.json. Fixed my file path, issue was resolved.

May be helpful for someone.

1
votes

Running

npm run scss
npm run start 

in that order in terminal solved the issue for me.

1
votes

In my case, the issue occurred after I switched from a git branch to another, references to some old files remained in the scripts inside "node_modules/.cache" directory.
Deleting "node_modules", "build" directories and "package-lock.json" file then issuing "npm install" command has fixed the issue for me

1
votes

I solved this error by simply creating a blank file at that location for which I got the error. If you are getting the error for a directory, You can try by creating empty directory also. All the best.

1
votes

I added PM2_HOME environment variable on a system level and now it works alright.

0
votes

[this is a helpful link on multer github][1]

but for me i have to create a public folder in the server folder also its like -cb(null,'public/'). [1]: https://github.com/expressjs/multer/issues/513

0
votes

Make sure your angular.json file has the "style" and "scripts" array as below (For Angular 12 and above):

"styles": [
          "src/styles.css",
          "./node_modules/bootstrap/dist/css/bootstrap.css"
        ],
"scripts": [              
          "node_modules/jquery/dist/jquery.min.js",
          "node_modules/bootstrap/dist/js/bootstrap.js"
        ]

Once this is done, Press CTRL + C and then ng serve

-1
votes

In my case

import { Object } from '../config/env';

gave me the error.

I solved it with change the address like this:

import { Object } from './../config/env';

-2
votes

Its happened with me. I deletes some css files by mistake and then copied back. This error appeared at that time. So i restart all my dockers and other servers and then it went away, Perhaps this help some one :)

-3
votes

I tried something and got this error Error: ENOENT: no such file or directory, open 'D:\Website\Nodemailer\Nodemailer-application\views\layouts\main.handlebars'

The fix I got was to literally construct the directory as it is seen. This means labeling the items exactly as shown, It is weird that I gave the computer what it wants.