I am trying to read a file using readFileSync, but I get ENONET no such file or directory… error
my website structure:
I tested 4 ways but none of them worked.
here is 4 ways(hello.js):
const fs = require('fs');
const path = require('path');
const way1 = fs.existsSync('./data.txt'); // false
const way2 = fs.existsSync(path.join(__dirname, 'data.txt')); // false
const way3 = fs.existsSync(('var/task/src/data.txt')); // false
const fileName = './data.txt';
const resolved = (process.env.LAMBDA_TASK_ROOT)? path.resolve(process.env.LAMBDA_TASK_ROOT, fileName):path.resolve(__dirname, fileName);
const way4 = fs.existsSync(resolved); // false
exports.handler = function(event, context, callback) {
callback(null, {
statusCode: 200,
body: JSON.stringify({
way1, way2, way3, way4
})
});
}
the result is false for all 4 ways.