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

185
Vistas
why adonis object stored in static file getting changed on doing operation on its imported value?

I am using adonis framework for server. I am storing an array of object in a file and using it in my code as datasource but when I am running a manipulation on imported variable of this array of object, it changes the value of that object for that particular server instance. why is this happening?

below is the code :

import { Ant } from "App/Utils/Ant";

export default class antcontroller {


public async antTocow(ants, color) {
    ants.forEach((ant) => {
      ant["color"] = color;
         });

    return ants;
  }

public async index(ctx: HttpContextContract) {

    let ants = Ant[country];
antToCow = await this.antTocow(
        ants.slice(0, 3),
        color
      );
return antToCow
    }
}
}

cowController

import { Ant } from "App/Utils/Ant";

export default class antcontroller {



public async index(ctx: HttpContextContract) {

    let ants = Ant[country];

return ants
    }
}
}

Ant.js

const ant = {
NEPAL: {
language: "nepaleese",
size:"big"
}}
module.exports = { ants };

on running cow api get call controller I get

{
language: "nepaleese",
size:"big"
}

then on running ant controller I get

{language: "nepaleese",
size:"big",
color:"black"
} 

then now on running cow controller i get:

{language: "nepaleese",
size:"big",
color:"black"
} 

color field should not be in cows call, why is it comming. does my file gets changed in memory for a given instance of server?

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