Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

188
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda