Closed sean-hill closed 8 years ago
Another idea, would be to group services and routes together like:
- app
index.js
- user
index.js
- create
- service.js
- route.js
- update
- service.js
- route.js
But I don't really like that approach as much.
I usually take a slightly diferent approach than 2 . i do the following:
app
index.js
index.js
services.js
route.js
index.js
services.js
route.js
Im using node4 so i just implement my services in a class and use Studio.serviceClass to load it all. If it happens of the service become really big, then you can break it in more subfolders, but for me, it is working really well this way.
This approach (as the second you discribed) has the advantage of being really easy to distribute, if i need different deploys for my services i could do the following
app
load_foo.js
load_bar.js
Just a minor change and are ready to distribute by functionality
Hey @ericholiveira!
Thanks. Would you mind screenshotting your file structure as an example? I'm a little confused at what you mean. Thanks :)
Also I don't see any docs for Studio.serviceClass
in the repo.
Oh, thx i will add it tonight. Anyway you can see it here: https://medium.com/adopting-microservices-architecture/nodejs-microservices-from-zero-to-hero-pt2-72fbb2a1b1c4#.dahyaklx5
(I will keep the issue open for a while if anyone wants to comment something on this )
Something like this (attaching this, because i only have my company code, so i prefer to avoid printing it) , on express.js i initialize express to use on the routes
Hey I was just curious what a good file structure would be for use with Studio and an Express API. I'm thinking something like this:
Under the services folder, they are group by Studio module's if appropriate, or just standalone files if the service doesn't need a module. Then each api route would have its own file, which would then require its associated service.
Thoughts? Also, what have you guys done?