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

187
Views
How to export a node.js function in an azure?

I have the following structure with 2 azure functions running separately in an azure function app:

- main_function_app
  - functions
    - Full_Stack
        - configAPI.json
        - configAPITest.json
        - function.json
        - index.js
    - Web  
        - configAPI.json
        - configAPITest.json
        - function.json
        - index.js
    - host.json
    - local.settings.json
    - package-lock.json
    - package.json
    - proxies.json
    - utils.js

I have the following content in the index.js from Full_Stack:

module.exports = async function (context, req) { 
    let element = req.body;
    const purchase_time = Number(element.purchase_time_);
    const type = "Full Stack";

    if (element.startswith('full')){
        async function getStatusPayload(purchase_time, offset);
    }

    async function getStatusPayload(purchase_time, type){
    if (purchase_time>0){
        context.log("Purchase time successful in " + type);
        }
    }
    context.res = {
       // status: 200, /* Defaults to 200 */
       status: 200
    };
}

I have the following content in the index.js from Web:

module.exports = async function (context, req) { 
    let element = req.body;
    const purchase_time = Number(element.purchase_time_);
    const type = "Web";

    if (element.startswith('web')){
       async function getStatusPayload(purchase_time, type); 
    }

    async function getStatusPayload(purchase_time, type){
    if (purchase_time>0){
        context.log("Purchase time successful in " + type);
        }
    }
    context.res = {
       // status: 200, /* Defaults to 200 */
       status: 200
    };
}

Both functions are almost the same and I want to refactor the getStatusPayload. I have created a draft in the utils.js file but I cannot test it in the either the full stack or web index.js because I don't know how to import it from azure. Also, I am not totally sure if code will even work once I am able to import it to full stack and web.

// utils.js
exports ={
    getStatusPayload: async function (purchase_time, type){
    if (purchase_time>0){
        context.log("Purchase time successful in " + type);
        }
      }
   }
}
module.exports = exports;

I also came around context.executionContext.functionDirectory which throws the current directory, but not sure if this might be helpful in in the solution.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To your question: require is a function we can use to import other modules:

// it looks like this
let util = require('./util.js');

and to export:

function getStatusPayload() {
    // Code here
}

module.exports = {
    getStatusPayload
}
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!