I've pretty much worked alone doing JS but I'm wondering, what's the best way or the proper way to structure your JS files in a project for everyone to understand it specially on big projects. I believe there was a similar question asked before but I couldn't find it. Thanks
Dong Nguyen
Web Developer
That depends on which pattern and/or framework you are using. Each of pattern/framework has several guidelines about convention and best practice.
For example, while building node-based presentation layer at server side, I often structure the JS files as below:
It's learned from MVC pattern. Note that in node.js, we don't care about 3rd party modules. If I have the special services, I would look them as workers and store them within /workers folder.
In browsers, I like to use RequireJS and module pattern. So it usually looks like below:
Please take a look on my skeleton for more info:
github.com/ndaidong/mdl-skeleton
If you use jspm or browserify, webpack, bower... you can see they store 3rd modules in the particular locations. For my case, I just store these resources within /js/packages folder.
It's my two cents. Almost all frameworks would suggest the best structure for your code. Just use the starter kit or skeleton they provide.