i would to know what's the best way between these two codes:
module.exports = function(){
require('fs').readFile..
crequire('./sockets.js').clients..
...
};
second:
var fs = require('fs');
var clients = require('./sockets.js').clients;
module.exports = function(){
fs.readFile...
clients...
}
I search the best way to optimize.
Thanks !
From performance point of view there is no difference, because require
is cached after first call. But still I think that the code is more readable when you declare imports at the begining of the script. Thus the second version is prefered, imho.