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

186
Vistas
How can I dynamically change an object that is set in another file?

I have a problem and need your help. I am currently working on a project in which I have to save a javascript object in an external file and export the whole thing via module.exports.

Now to my problem and I would now like that another file changes a certain value in my object. This is also possible with:

OBJECT.VALUE = "YOUR NEW VALUE"

Problem is that it now works in this session but the object should permanently change this value means Node.js now has to change this value in the object file too.

I guess I have to use the fs library but I don't know how exactly? I would like to keep the structure of the object means the script should only change the value

Here you have the Object File:

const Core = new Object();

Core['config'] = {

    ['test'] : "Test"

}

// Export the Core
module.exports.Core = Core;

What i tried in other File:

const { Core } = require('./settings/Core.js')


Core['config']['test'] = "MY NEW VALUE"
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There are several ways you could go about this.

Create a getter and setter function in your object file and export them.

function setObject(field, newVal){ 
  Core.config[field] = newVal
}

function getObject(){
  return Core;
}


module.exports = {setObject, getObject}

In your other file call the function.

const {setObject, getObject } = require('./settings/Core.js')

Now just use the functions to retrieve or update the object

setObject("Test", "NewValue")
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