Answer the question
In order to leave comments, you need to log in
Are there any "features" in node.js require?
Recently switched to node c php. I am writing a small REST server using ExpressJS. For simplicity, I decided to write only a few routers (so as not to prescribe for each method). Here is an example:
app.get('/v:version/:resource.:method',function(request,response){
// подключаем метод
var method = require('./'+request.params.resource+'.'+request.params.method+'v'+request.params.version+'.js')
method.call(request,function(error,result){
// отдаем данные или ошибку
})
})
Answer the question
In order to leave comments, you need to log in
There will be no leaks of require itself. But the trouble is in your approach of the following character. require is synchronous. You are using a synchronous method in an asynchronous function - this is basically bad. All require calls must be placed at the beginning of the module so that they are called when the module is loaded. Read about good node.js practices, including on Habré. The conclusion is simple - synchronous code is evil.
The memory shouldn't leak, @virpool is right. I would not recommend using requirejs for a node - it makes debugging a lot harder (when you really need to look for memory leaks).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question