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

202
Vistas
exports variable didn't change after operate by required

I store variables in config.js, and I import those variables to different function with different file.
Then I import those functions and variables to main app.js.
The issue is when I exports as obj, values " could be changed " after call those functions
But I exports as variables directly, values " couldn't be changed " after call those functions

how can I exports variables directly ??

Here is an example below

//config.js
exports.varNum = 100;
exports.varBoolen = false;
exports.obj = {
    name:"Kai",
    age:31,
    single:true
};
// funcA.js
let { varNum, obj } = require("./config")

module.exports = function add (){
    varNum += 1;
    obj.age += 1;
}
//funcB.js
let { varBoolen, obj } = require("./config")

module.exports = function change (){
    varBoolen = !varBoolen;
    obj.single = !obj.single;
}

//app.js
const express = require("express");
const app = express();
let { varNum, varBoolen, obj } = require("./config")
let add=require("./funcA")
let change=require("./funcB")

app.get("/", (req, res) => {
    res.json({ status: "ok", data: { varNum, varBoolen, obj } })
})
app.get("/add", (req, res) => {
    add();
    res.json({ status: "add" })
})
app.get("/change", (req, res) => {
    change();
    res.json({ status: "change" })
})
about 4 years ago · Juan Pablo Isaza
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