project_mern_memories icon indicating copy to clipboard operation
project_mern_memories copied to clipboard

why do you need to make an instance of express() also in the conrollers

Open GuyTdev opened this issue 2 years ago • 2 comments

https://github.com/adrianhajdin/project_mern_memories/blob/6011a17ce778e50e0f46b2ffe98ad3edb8191ed0/server/controllers/posts.js#L6

why do you need to make an instance of express() also in the conrollers. It already done in routes folder.

GuyTdev avatar Apr 05 '22 14:04 GuyTdev

Cause express works like this. So, of course, he can juste import Router from express, but in that tutorial, the goal is to learn a bit about back-end developpement and more about MERN projects, but for beginners it's better to know how it works. But I'm agree with you, we haven't got to make a new instance express.

I don't know if you understand correctly all I say ^^"

ezequiel-fr avatar Apr 05 '22 14:04 ezequiel-fr

As far as I understand the purpose of controllers folder is only to implement the logic of the routes folder. And if we create an instance of express as a router in the routes folder, it doesn't necessary neither to make another instance nor to import router in the controller folder. The imports is from the other direction: we import the logics functions from controllers folder to the routes folder

GuyTdev avatar Apr 05 '22 18:04 GuyTdev