Why is project architecture so crucial?
Having a proper foundation for our project architecture is critical for the project's longevity ...
For further actions, you may consider blocking this person and/or reporting abuse
Good post.... What I do sometimes is to wrap the aforementioned folders inside a src folder.
This is usually a good practice in my opinion. Then, you can add config files, editor configs, etc on the root level of the project. Additionally, you can specify src/ app/ and then storage/ for any user generated files or logs. It just makes everything cleaner.
Check the repo of what i most of the time doo too github.com/nermineslimane/Node-exp...
Feel free to contribute to it if you want too, I prefer tp store user generated file unde /tmp since they're most of the temporary and sometimes i save them under a folder named after the userId or the UserName
Can I know what ur project is about. All I could find is empty files in routes. If u could specify the agenda we could contribute and improve ur repo
yes most of the time i doo that too, i wrap them inside /app , check the repo here github.com/nermineslimane/Node-exp...
It is even more useful to divide the logic into modules. Generally speaking, the module should have a set of classes with a narrow specialization. A well-designed module does not have to be a "universal combine".
For example, a security module has a narrow specialization - access security and application management security. Here should not be declared classes which translating messages into different languages, sending mail, writing logs, etc.
When a particular module is tied to a specific URL, it's also good practice, and it can also be considered as a "narrow specialization". For example, one module can process all HTTP requests to
/api/users
, another module can process/api/posts
.Hi, thanks for sharing. I like the structure.
Just did a quick check how my last express project was structured.
The project was quite complex. I had a routes folder too.
But the exports of each folder was an own router object.
Then in the root of the project dir I had the app.js that put the routers together like so:
One can say that each routes folder was a project on it's own this way like independent.
Great for microservices if you decide to put it into separate services.
I recommend to read this github.com/goldbergyoni/nodebestpr..., this will guide you and provide a lot of useful information.
I also suggest to change the title to How to structure your next project, because i think that frameworks and programming languages should not control the structure and the architecture of our projects, for example we can follow the same structure/architecture using python , java , c# or go.
and thank you so much for this amazing post
“The .env file should never be pushed to your github repo !”
May I know what is the standard way to use or recreate this env file after we pull the code from GitHub or when the app is deployed in a container?
Find out all about .env in this article dev.to/nermineslimane/what-is-env-..., concerning the fact that it should never be pushed to version control it's purely and solely for security reasons since it holds info about the secret keys of your app that shouldn't be shared so for that purpose every deployement way has it's specific way to add the .env file , in your case what are you using to deploy the application ?
Thanks for the reply and link.
I used docker to containerize the node.js express app and used GitHub action to add the .env file in the container. I googled this method when I was doing the DEV project. But I think that if someone gets the docker image then they can easily find out the .env file. :D
So I wanted to know what’s the industry standard used to deploy this .env file.
docker-build.yml:
Looking for the answear for you will you allow to post the subject on a forum ? maybe we'll both find the stardard for this ?
Yes of course. 👍🏼
wel thank you and here's the link to the stackexchange post if anyone wants to contribute feel free softwareengineering.stackexchange....
It's preferable to put your business logic in a service layer that can access the DAL (data access layer) for loose coupling reasons like:
What if you have a Rest API and want to make an MVC version or vice versa use service layer so you don't repeat your logic
What if you need to change a third party service like moving from Google cloud storage to AWS S3, use service layer so you don't have to update every function using this service, you will only need to update one file (this service file)
I would use a validation layer before the controller which validates the request body, can be done with something like JOI, express-validator, express-validation, etc..
I would also import & export related layer file from a single entry point like:
controllers/
services/
and so on for other folders.
So, in index.js, you import other services/controllers and export an object with all services/controllers.
Finally, I suggest reading about dependency injection and its advantages.
I use this method for the routes, i create one single entry point for all my routes like follows
/routes
-exemple1.routes.js
-exemple2.routes.js
-index.routes.js
-exemple3.routes.js
and in my index.routes.js I export all the routes
Thank you for the clear examples and explanation for the file structure.
you're welcome, feel free to contact me in case you have question !
Thanks for this. It’s always nice seeing someone share their app structure. It helps me warp my brain around concepts better.
Hi All,
In which folder I have to place the logger (winston)
i.e
src/logger
src/utils
Please suggest