I read that when you require
a file, node.js reads the file from disk only the first time, and after that caches it.
When are items removed from the cache ? If I require
1000's of different files (each only once, within a methods scope), then can my server run out of memory (because of the cache), or does the cache have a fixed size, after which it removes items from the cache ?
function foo(var bar){
var shoe;
if (bar === "blue"){
shoe = require("./somefile.js");
}else if (bar === "red"){
shoe = require ("./someotherfile.js"){
} //.....etc m
//Do something with shoe etc...
}
I ask because, I have many different files stored as JSON, and using require
is more convenient than using fs
to create the object.