Search code examples
expressamazon-ec2pdfkitnode-pdfkit

npm pdfkittable ENOENT for reading file from locally in EC2


My Express App Ending up in the following error while running code of pdfkittable in AWS EC2, but it was working fine in my local system

.

Error: ENOENT: no such file or directory, open './images/145.jpg'
May 17 01:51:56 ip-172-31-15-xxx my-node-server: at Object.openSync (node:fs:585:3)
May 17 01:51:56 ip-172-31-15-xxx my-node-server: at Object.readFileSync (node:fs:453:35)
May 17 01:51:56 ip-172-31-15-xxx my-node-server: at getImageBuffer (/home/ec2-user/miassessment/pdf-service.js:41:15)
May 17 01:51:56 ip-172-31-15-xxx my-node-server: at Object.miReportGenerator (/home/ec2-user/miassessment/pdf-service.js:47:25)
May 17 01:51:56 ip-172-31-15-xxx my-node-server: at Process.reportGeneration (/home/ec2-user/miassessment/backendFuntions.js:489:20)
May 17 01:51:56 ip-172-31-15-xxx my-node-server: at processTicksAndRejections (node:internal/process/task_queues:96:5) {
May 17 01:51:56 ip-172-31-15-xxx my-node-server: errno: -2,
May 17 01:51:56 ip-172-31-15-xxx my-node-server: syscall: 'open',
May 17 01:51:56 ip-172-31-15-xxx my-node-server: code: 'ENOENT',
May 17 01:51:56 ip-172-31-15-xxx my-node-server: path: './images/145.jpg'
May 17 01:51:56 ip-172-31-15-xxx my-node-server: }

The file is existing in /images directory inside the root directory.

Image file to read exist in

/miassessment/images/145.jpg

Code Running in

/miassessment/pdf-service.js

Solution

  • Give absolute path of image '/home/ec2-user/miassessment/images/145.jpg' for EC2.