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

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