Answer the question
In order to leave comments, you need to log in
Is there an autoloader for node.js like php?
Actually a subject.
I remember a dozen years ago, php also had to write require and include every time in each file, until the autoloader appeared.
Does node.js have something similar?
Answer the question
In order to leave comments, you need to log in
You don't seem to understand the architecture of node
In php, module autoloading is used to speed up loading, since the script process lives for the duration of the request and dies when it completes
. In node, the process lives forever (does not die between requests) and processes many requests, with each request modules do not connect again, they are already connected. Moreover, when connecting, the module is cached in memory, by connecting it again in another place, you do not execute it again, but use the already executed module.
So what are you doing wrong if you have such a question
// при старте делаете просто
global.api = {};
['fs', 'os', 'util', 'http'].map(function(m) {
api[m] = require(m);
});
...
// теперь в любом файле пишете
api.fs.readFile(...);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question