Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

355
Vistas
ENOENT: no such file or directory Nodejs

I am trying to import images I have stored in a folder called resources located under the server section.

When I place the images in the app folder on my local drive, it works fine, but since this has to be deployed to our live server, it makes things hard to have to copy files back and forth.

The error I get:

Error: ENOENT: no such file or directory, open '../../resources/cp_pdf_logo.png' at Object.openSync (node:fs:585:3) at Object.readFileSync (node:fs:453:35) at RouteEmails.orderAuth (C:\Development\kaizen\server\routes\emails\file:\C:\Development\kaizen\server\routes\emails\func.js:187:43) at RouteEmails.sendMail (C:\Development\kaizen\server\routes\emails\file:\C:\Development\kaizen\server\routes\emails\func.js:430:17) at RouteOrders.orderAuthorizedMail (C:\Development\kaizen\server\routes\orders\file:\C:\Development\kaizen\server\routes\orders\func.js:840:24) at processTicksAndRejections (node:internal/process/task_queues:96:5) at RequestRouter._routeRequest (C:\Development\kaizen\server\socketController\file:\C:\Development\kaizen\server\socketController\requestRouter.ts:64:34) at RequestRouter.processMessage (C:\Development\kaizen\server\socketController\file:\C:\Development\kaizen\server\socketController\requestRouter.ts:43:9) at Socket. (C:\Development\kaizen\server\socketController\file:\C:\Development\kaizen\server\socketController\socketClient.ts:62:7) { errno: -4058, syscall: 'open', code: 'ENOENT', path: '../../resources/cp_pdf_logo.png' }

Here is an example of my code:

let ordercplogo = this.base64_encode("../../resources/cp_pdf_logo.png")
    let orderthankyoulogo = this.base64_encode("../../resources/thankyou_logo.png")
    // let ordercplogo = this.base64_encode("/app/resources/cp_pdf_logo.png");
    // let orderthankyoulogo = this.base64_encode("/app/resources/thankyou_logo.png");

The commented-out section is what works, but from the image below you can see that I have these files stored inside the app.

enter image description here

Can anyone tell me what I'm doing wrong?

PS. I have also tried to import the images above with

const logo1 = require("../../resources/image.png")

but also doesn't work and throws another error.

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Your function probably tries to find the image relative to the working directory. It makes a difference if you were to do cd /; node /app/index.js or cd /app; node index.js. The working directory may be different in your live environment than locally.

There are a number of functions to help you find the path to a file in the built-in path module.

Let's assume you're in a file called routes/companies/a.js:

const { resolve } = require('path');

this.base64_encode(resolve(__dirname, "../../resources/cp_pdf_logo.png"));
// Will find the absolute path to the file.

( path.relative documentation page )

In CommonJS files (files that use require()) the value __filename always refers to the file it's in, rather than the main script file (so /app/routes/companies.a.js in this example) and __dirname is the directory it's in. That's the same value, without the a.js part.

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda