The idea is to use the principle of separation of concerns to move the business logic away from the node.js API Routes.
You may be tempted to just use the express.js controllers to store our business logic of your application, but its not a good way.
Use a service layer for your business logic it will be very good.
NodeJS/Javascript have a characteristic that some people find usefull, but it can make you go deep in the wrong way, and this is the freedom of choose how you want to structure your project (Remember that NodeJS is not a framework like Rails or .Net). Only the experience working in different projects will let you define the best structure for every situation.
I suggest the follow my structure.
- Opne terminal
- run
git clone https://github.com/Abdul-majid-ashrafi/nodejs-structure.git
- run
cd nodejs-structure
- run
npm install
- run
npm start
Happy Coding :)