JavaScript naming conventions when working with nodejs

I work a lot more with JavaScript in node.js. My application has the following general β€œclasses” that are used.

Server side:

  • Libraries
  • Models
  • Utilities
  • Routes

Client side (backbone.js):

  • representation
  • Models
  • Collections

The client side is pretty straightforward. I name all the files related to what they are, such as UserModel.js, UserView.js, UserCollection.js, etc.

However, the server side becomes more dirty. For instance:

Models are associated with MongoDB collections. Each model is simply a shell for various functions. If I have a collection of users, I have a collection called users, my model Users.js.

, , Users.js, .

users, , .

URL. , /account/, account.js - .

. util.js, , , .

, , "", /.

+3
3

- . , .

, , . , UserRoutes.js, UserModel.js , , UserLib.js .

node.js .js. , , user.routes. .

+5

, , , , , , , ... ?

, .

+1

In fact, I am doing what you are doing now. I have folders for models, routes, views, and controllers. Then I have a user.js file in each folder. When I need to fix a bug or implement something to do with users, it's pretty easy to figure out where I need to go.

I think it would be strange if I tried to come up with smart names for all of these files when they all implement different aspects of the related thing.

0
source

All Articles