For some reason, I am encountering an error when trying to read a file using fs.readFileSync within a Template literal. The specific error message that I'm getting is:
Error: ENOENT: no such file or directory, open './cookie.txt'
at Object.openSync (node:fs:590:3)
at Object.readFileSync (node:fs:458:35)
at new SteamgiftsBot (C:\Repositories\steamgifts-bot\src\steamgiftsBot.ts:15:19)
at Object.<anonymous> (C:\Repositories\steamgifts-bot\src\index.ts:3:1)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Module.m._compile (C:\Repositories\steamgifts-bot\node_modules\ts-node\src\index.ts:1618:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Object.require.extensions.<computed> [as .ts] (C:\Repositories\steamgifts-bot\node_modules\ts-node\src\index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:827:12) {
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: './myfile.txt'
}
Here is my current code snippet which is not working as expected:
headers = {
Cookie: `PHPSESSID=${fs.readFileSync("./cookie.txt", "utf-8")}`,
};
This was the old code snippet that was working fine:
headers = {
Cookie: "PHPSESSID=" + fs.readFileSync("./cookie.txt", "utf-8"),
};
You can find the commit related to this issue here: https://github.com/butilka123/steamgifts-bot/commit/9ce373868d40aa21c94fe1e6e61b0c804dfe742a
I am unsure why this error is occurring and would appreciate any help in resolving it.
Thank you in advance for your assistance.