mercredi 15 avril 2015

how to make nodejs exports a static object

i wonder to know is the code below runs right


a.js:



var obj = {
name: 'a'
};
module.exports = obj;


b.js



var b = require('./a');

module.exports = b;


c.js



var a = require('./a');

console.log(a); // {name: 'a'}

a.name = 'b';
console.log(require('./a')); // {name: 'b'}
console.log(require('./b')); // {name: 'b'}


so, i can change a module exports from outside


if i cange the a.js to a.json


a.json



{
"name": "a"
}


i got the same result


how can i export a module can't modify or override form outside


Aucun commentaire:

Enregistrer un commentaire