aishwat singh aishwat singh - 10 months ago 39
Javascript Question

Does require in node js, updates value at run time?

I have something like

var some_data=require('../objects/some_data.json');

//something here to change data of some_data.json - fs.write
//vl this affect value of some_data at this point ?

Does require keep active reference to files OR just reads it once while requiring ?

If it keeps active ref , how can i retain old value of some_data

mmm mmm

It loads the file, how it is on start. It doesn't take any changes you are doing to the json file.

For example, run this

var b = require("./a.json");
for (var i = 0; i< 1000000; i++) {

with this json a.json

  "a": "b"

And change the value whilst in the loop - or delete the file. It will still work.