> Is there any reason why I should do the same?

No.
 
In very large applications it might make sense to include controllers like this, but if you're just starting, you don't need that. As for models, requiring a file without assigning its returning value means that that file have side effects. It is rarely justified (except for tests), and if you have the whole folder of such files, it smells really bad.
 
I'd suggest to avoid code like that.
 
 
22.01.2014, 00:00, "gabor laser raz" <[email protected]>:

Hey Guys,

 

My name is Gabor and I started learning _javascript_, Node.js with Express last December. My problem is I don’t know anybody who works with it. So I thought I can ask some questions here. I hope I’m not wrong here!

 

I hope you understand my questions because I’m from switzerland and I’m not so good with grammer :).

 

My question at the moment is simple. I saw in many code examples that they bootstrap the models and sometimes the controllers. This code looks then like this.


//Bootstrap models

var models_path = __dirname + '/app/models';

var walk = function(path) {

    fs.readdirSync(path).forEach(function(file) {

        var newPath = path + '/' + file;

        var stat = fs.statSync(newPath);

        if (stat.isFile()) {

            if (/(.*)\.(js$|coffee$)/.test(file)) {

                require(newPath);

            }

        } else if (stat.isDirectory()) {

            walk(newPath);

        }

    });

};

walk(models_path);

 

// Bootstrap controllers

var controllers_path = __dirname + '/app/controllers'

  , controller_files = fs.readdirSync(controllers_path)

controller_files.forEach(function (file) {

  require(controllers_path+'/'+file)(app)

})

 

 

Is there any reason why I should do the same?

 

--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to