Structuring a NodeJS app using Angular and NodeJS Tools for Visual Studio

364 views Asked by At

I would like to know how do you usually organize your application structure when building a NodeJS application using nvst. When I create my app it automatically build up this structure for me: enter image description here

So, the first thing that came to my mind was, where should I put my controllers and how do I connect them with the routes and views?

Also, how can I organize my unit testing logic?

1

There are 1 answers

0
Amy B On

An NTVS angular app is still just an angular app. The advice in AngularJS application file structure applies.

Going further, General principle: You should be able to find what you're looking for without excessive drilling or scrolling.

Schemes:

  • for smaller apps, folder by type: controller; service; model
  • for larger apps, folder by function: user; cart; search; grid

I lean toward folder by function, as it keeps files that may need to be modified at the same time together.

As for unit tests, I have seen either myfile.test.js or myfile.spec.js sitting right beside myfile.js. If you do not include the test files in the index.js, then they won't be loaded and don't cause a problem.