Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

202
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!