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

201
Views
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
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!