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

203
Views
la variable de exportaciones no cambió después de operar por requerido

Almaceno variables en config.js e importo esas variables a diferentes funciones con diferentes archivos.
Luego importo esas funciones y variables a main app.js.
El problema es cuando exporto como obj, los valores " podrían cambiarse " después de llamar a esas funciones
Pero exporto como variables directamente, los valores " no se pudieron cambiar " después de llamar a esas funciones

¿Cómo puedo exportar variables directamente?

Aquí hay un ejemplo a continuación

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