{"id":1974,"date":"2013-12-02T07:40:07","date_gmt":"2013-12-02T13:40:07","guid":{"rendered":"http:\/\/www.wiredprairie.us\/blog\/?p=1974"},"modified":"2013-12-03T07:44:35","modified_gmt":"2013-12-03T13:44:35","slug":"loading-models-in-nodejs","status":"publish","type":"post","link":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/1974","title":{"rendered":"Loading Models in NodeJS"},"content":{"rendered":"

I\u2019d answered a question<\/a> on StackOverflow about where to put \u201cmodels\u201d in a NodeJS project. I wanted to elaborate on the simple auto loader I use to load a folder full of models (and I use this pattern other places as well). Normally, I create a folder called models<\/strong>:<\/p>\n

\"image\"<\/a><\/p>\n

Inside the Models folder, I have a file called, models.js<\/strong>. <\/p>\n

Inside another module (like app.js<\/strong>), I\u2019ve got a line of code that looks like this:<\/p>\n

\nvar<\/span> models = require('.\/models'<\/span>).initialize(app, services);<\/pre>\n