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

207
Vistas
How to read a file from an Azure Function in NodeJS?

I have an Azure function and a file called configAPI.json which are located in the same folder as shown in the image below.

enter image description here

I want to read the latter with the following code based on this post How can i read a Json file with a Azure function-Node.js but the code isn't working at all because when I try to see if there's any content in the configAPI variable I encounter undefined:

module.exports = async function (context, req) {
    const fs = require('fs');
    const path = context.executionContext.functionDirectory + '//configAPI.json';
    configAPI= fs.readFile(path, 'utf-8', function(err, data){
        if (err) {
            context.log(err);
        }
        var result = JSON.parse(data);
        return result
    });

   for (let file_index=0; file_index<configAPI.length; file_index++){
       // do something

  }
context.log(configAPI);
}

What am I missing in the code to make sure I can read the file and use it in a variable in my loop?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

functionDirectory - give you path to your functionS app then you have your single function

I think you should do:

const path = context.executionContext.functionDirectory + '\\configAPI.json';

In case you want to parse your json file you should have:

const file = JSON.parse(fs.readFileSync(context.executionContext.functionDirectory + '\\configAPI.json'));

PS. context has also variable functionName so other option to experiment would be:

    const path = context.executionContext.functionDirectory + 
+ '\\' +context.executionContext.functionName + '\\configAPI.json';
about 4 years ago · Juan Pablo Isaza 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