Read local file (fs.readFileSync)

#1

Hi,

If I create a file local to my container / sandbox:

./public/my-file.html

And then try and read with any of the following:

require(‘fs’).readFileSync(require(‘path’).resolve(‘public/my-file.html’));
require(‘fs’).readFileSync(require(‘path’).resolve(process.cwd(), ‘public/my-file.html’));
require(‘fs’).readFileSync(require(‘path’).resolve(__dirnme, ‘public/my-file.html’));

I get:

Error: ENOENT: no such file or directory, open ‘/public/my-file.html’

What am I doing wrong?

0 Likes

#2

Hi Supasympa :wave:

Unfortunately there is a bug in the current version that causes the working directory to be incorrect. For you to be able to read that file you would need to provide the absolute path to that file. You can extract the path to current project directory from module.paths.

The build with the fix for this bug has already been sent for review, the new version should be out by Sunday or Monday.

Thanks for reporting Supasympa :slight_smile:

0 Likes

#3

This is now fixed :slightly_smiling_face:

0 Likes