Module FS's Interesting Error

I have used this code:

const memoryFile = JSON.parse (fs.readFileSync('../Memory/blabla.json'))

And I have that file, but it errors:

Error: ENOENT: no such file or directory, open '../Memory/blabla.json'

How I can fix this?

Hello @eray6421,

Look at the error: no such file or directory. Have you checked twice the path you using?

fs uses absolute paths. Eg. app/src/some/abs/path.js, not ../rel/path.js


In that case, you can either use the path module or the __dirname keyword.

These were worked, thanks you! :slight_smile:

1 Like