Cloud Code: file not found when invoking deployed endpoint

I have written a function which reads a file. It’s a simple small text file, and when debugging it works fine. After deploying, it is not found, though in Cloud Code (Coding) tab it seems to be uploaded and in a correct structure. Am I doing some wrong here?

const privateKey = fs.readFileSync(
			"certs/AuthKey_xyz.p8",
			"utf8"
		);

File tree in my computer:

File tree after deploying to BL:

Getting this error when invoking the function (tried both with ../ and without it):

Any idea how to make it work?

Thanks,
Justinas

Hi @Justinas_Grazulis

try to compose an absolute path

const privateKey = fs.readFileSync(
  path.resolve(__dirname, '../cert/AuthKey_xyz.p8'),
  "utf8"
);

It seems to have worked, thanks for the support @vladimir-upirov !

1 Like