Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

186
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda