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

190
Vistas
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 Respuestas
Responde la pregunta

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 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