adrianhajdin / project_mern_memories

This is a code repository for the corresponding video tutorial. Using React, Node.js, Express & MongoDB you'll learn how to build a Full Stack MERN Application - from start to finish. The App is called "Memories" and it is a simple social media app that allows users to post interesting events that happened in their lives.
https://youtube.com/playlist?list=PL6QREj8te1P7VSwhrMf3D3Xt4V6_SRkhu
5.03k stars 1.85k forks source link

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

Open GuyTdev opened 2 years ago

GuyTdev commented 2 years ago

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.

ezequiel-fr commented 2 years ago

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 ^^"

GuyTdev commented 2 years ago

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