r/javascript • u/dhevd9392 • Apr 09 '23
Building RESTful APIs with Node.js and Express
https://abhishekdhapare.hashnode.dev/building-restful-apis-with-nodejs-and-express10
u/frosty-the-snooman Apr 09 '23
You should rename your controllers to user.controller.js and your model to user.model.js. For small pages, it is burdensome to spec each route, just use routes.json. Specifying utilities is not really a best practice, you should arrange the utilities into a service... like auth.service.js.
Semantic naming will save you countless hours and mistakes. Just sayin
2
u/frog_slap Apr 13 '23
Curios as someone who is learning why you put full stops in the file name? I have a project where I don’t use full stops, if I’m consistent will there be any differences?
2
u/frosty-the-snooman Apr 13 '23
Sectioning the file names as <feature>.<purpose>.<file type> allows another dimension to filtering. You assumed all <feature> go into a space. If you keep the current pattern, your file architecture will be confusing after adding unit tests, assets, proxies, route guards, readmes, etc. This is a great place to start, but once you have 5 unique experiences and begin defining special user types within your app, your plan will start to fray. Once other devs want to add, that fraying will become an unraveling, probably requiring a refactoring.
The goal is to decouple features such that you can easily plug them into other apps without much legwork, update that feature without adding risk to other features, and of course show or allow toggling of features as "on" or "off" depending on the needs of the business. Your project is so small that it's not obvious yet, work on it for another year with one other dev and get back us on what works and doesn't.
2
u/frog_slap Apr 13 '23
I see, this is really interesting. Thanks a lot for explaining!
2
u/frosty-the-snooman Apr 13 '23
Here are some notes from angular, I can't seem to find any other frameworks that want to set or own naming conventions. You are right tho, as long as there is a standard, it doesn't have to exactly match someone else's. But for knowledge sake:
2
u/frog_slap Apr 13 '23
Thanks again. I just finished my first real experience of team/collab development recently and I took away more about like writing code so it can be interpreted etc correctly by other devs than I did actual technical knowledge. It was really interesting and is honestly so important looking back, so im eager to try and set up some good principles from the start
17
u/ShavaShav Apr 09 '23
GPT-generated article.
Also, we don't need any more "Hello World" express app examples - the express docs are just fine for this. You should have got ChatGPT to generate something a bit more complex.