Learn MVC Pattern with ExpressJS and NodeJS - Tutorial Beginner
Вставка
- Опубліковано 28 вер 2024
- In this video I will show a simple example on how to use MVC in an Express backend. MVC is a design pattern where you divide your project into Models, Views, and Controllers. Since this is a beginners tutorial, we will be structuring everything very simply, and more advanced designs might require more work.
-
Please leave a comment on what topic you guys want me to cover next!
-
👕 Programming Merch: teespring.com/...
💻 PedroTech Discord: / discord
-
Social
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
Website: machadopedro.com
Twitter: / pedrotech_
Linkedin: / machadop1407
Instagram: / _pedro.machado_
Github: github.com/mac...
Email: machadop1407@gmail.com
Tags:
- Axios
- MVC
- NodeJs
- ExpressJs
- ReactJS Tutorial
- ReactJS and MySQL
- NodeJS Tutorial
- API Tutorial
I really loved that you didn't cut out that part where the error happened. Shows the realities of coding.
Your videos are really simple and to the point, it's really easy to understand👍🏻
Thank you for the excellent explanation on MVC pattern. I was doing a refresher on backend development and was lost on the reason behind folder names. 😅
Nice & easy explanation
Thank you!
good explanation
simply brilliant !!
Thanks for the video :) Question: What code goes in the models folder?
Data
Database collection schemas and models
I understood the concept. Just use the word "basically" less next time.
Nice video 😁
Thanks 😁
thank you!!@@ Thanks to your video, i could understand easily what mvc is
Hi ,where to mention module.exports=get
salve pedro, teu inglês é mt bom
Vlww mano kkkkkk
@@PedroTechnologies é nós, me ajudou numa prova q eu to fazendo pra uma vaga kkkkkkk vlw maninho
Thank you so much bro ❤️
Than you for watching!
@@PedroTechnologies I have doubt about the model, can you give example for any random query?
@@ajaychawda682 I am sorry if it sounded confusing! There are two ways you can do this, if you are using an ORM like sequelize or mongoose, I would recommend putting the tables inside of the models folder and doing any type of query (ex: User.getById()...) in the controllers file. But If you are not using an ORM, I would recommend writing all the queries on the Models folder. When I say query I mean for example: db.query(
`INSERT INTO user SET
name = '"name',
password ="password",
callback
)
@@PedroTechnologies I am using MySQL ,the model will be collection of queries in the object format ? If I have to use multiple queries for perticular model. I mean similar to controller file as you created in this video , key value pair and export whole object ,and depending on condition execute specific queries from model. 😓 sorry for asking you multiple questions .actually I'm working on MVC for the first time.
Thanks
That is the basic idea. You would export an object similar to the controller one where it would include all the queries. I found this example which is really good: github.com/wrideveloper/express-mysql-crud-mvc/blob/master/model/Biodata.js
😍😍🤗
would love to see a full project made in mvc pattern
No matter how good your explanation is, if your goal is to get people to learn, you need practical examples. They can be simple, but they need to be practical. In your case, the intention is very good, but it may be that your video does not reach the audience that is starting, due to the very abstract explanations, and also does not serve for those who already know some things about the subject.
That's just you, everyone learns differently, because I am a beginner and loved his explanation.
Helpful video! Here from The Odin Project :)
teach smooth and easy intesting
node:internal/modules/cjs/loader:1146
throw err;
^
Error: Cannot find module '..//controller//usercontroller'
Require stack:
- C:\Users\karth\OneDrive\Desktop\mvc
oute\user.js
- C:\Users\karth\OneDrive\Desktop\mvc\index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
at Module._load (node:internal/modules/cjs/loader:984:27)
at Module.require (node:internal/modules/cjs/loader:1231:19)
at require (node:internal/modules/helpers:179:18)
at Object. (C:\Users\karth\OneDrive\Desktop\mvc
oute\user.js:3:18)
at Module._compile (node:internal/modules/cjs/loader:1369:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
at Module.load (node:internal/modules/cjs/loader:1206:32)
at Module._load (node:internal/modules/cjs/loader:1022:12)
at Module.require (node:internal/modules/cjs/loader:1231:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\karth\\OneDrive\\Desktop\\mvc\
oute\\user.js',
'C:\\Users\\karth\\OneDrive\\Desktop\\mvc\\index.js'
]
}
Node.js v20.12.2
i had this error.pls give suggesstion
Amazing video! can you please make one where you explain it in more detail? Thanks!!
Yes! I've been planning on doing an update!
Recommended ua-cam.com/video/A8Er0SDjp9Y/v-deo.html
Really loved that you added the bit where you made an error, shows that even experienced programmers like yourself can make mistakes, and it's not something that people should be scared of, but accept that it's normal and one way to learn!!
The whole require thing really threw me off for abit being so used to import 😂🤦♂️
Kkkk eu acompanhando o vídeo e me perguntando que espécie de americano tem o nome de Pedro Machado... Kk
sorry but i don"t like your explanation, i expected at least an example ...
Hello Pedro, I have a question... I have a function middleware in file routes.js. How Can I treat this function in MVC? Should It in controller too? Thanks by the video.
Hey, you can create a middlewares folder. I recently posted a video talking about folder structures, if ur interested! I talk a lot about the mvc model there!
Ok, thanks! I will watch this video.
How many came here from Odin Project?
router has been depreciated in new version of express
Hey Pedro, i am new to MVC pattern, and your video confused me a lot. In this case, the routes wouldn't be the controllers? and the controllers that you made wouldn't be model? Great Video!
Im new to javascript on the backend, so you're telling me the javascript idiots put the http request and the response handling inside the controller classes or is it just you?
Why not just rename the router file as a controller? For me is just a additional file without a real meaning. Then create a folder for the dtos and another for the business logic
Perdo ..your latest video is private🤔
Yeah hahaha For some reason it took a bit to process the HD version so it was available only for 360p. SO I made it private till it finished processing. Its public now!
@@PedroTechnologies oh...coool
It helped me a lot bro. I have my first commercial project that I'm the only programmer, without any help.
This is what I needed to structure my project as simple as possible.
Thanks so much!
Same here bro!
what about model?
How to use Model I really need to understand I am working on a project and I am not getting it at all. I am not allowed to use ORM can you kindly help me with it.
this is very far into the future but MVC is an architectural pattern and not a design pattern
Great video nevertheless, got a lot from it
Hello sir
Kindly make a video on crud operation using this MVC pattern
Thanks, can you explain how to work with models too? In this you just explain the controller.
Yeah, i mad this video a while ago and I din't go too much in depth, but I plan on making another one!
@@PedroTechnologies can't wait 👍😁
@@PedroTechnologies Is it out yet ?
thanks
thanks
Why model not created
❤️❤️❤️
I have been told not to run mvc on node. there is and equivalent for node.
Interesting, why would you not be able to use node? You can use other backend languages and frameworks like python / flask or golang.
@@PedroTechnologies There are many articles saying mvc is to sloooow to build a social network (trust me, it will choke under load ). Node is used but MVC is replaced with the node equivalent.
@@MichaelGuy I get what you mean but MVC is just a design pattern, and not a language. I believe the articles say that nodejs is too slow for a web server (which in theory is true depending on the project).
@@PedroTechnologies Yes and No. Their base is massive with lots of different parts of architecture doing different things.
Google mail uses MVP (Model View Presenter) or at least I believe they do, because it is better for dynamic web pages.
MVC is a buzzword, and while it has value in some architectures, it can be very limited, especially since most people see the Model as single entities.
Google search utilizes C code (at lest in part). While C can do MVC, the point of using C is often speed, so architectures like MVC tend to slow things down, defeating the value of using C.
MVC can be cumbersome, extensive and problematic, which is why it is yesterday’s buzz word. In it’s simplest for it is not bad for basic web applications, but as you get more intense it can become a big issue.
That is not to say they do not or cannot use MVC architecture in parts of their massive organizations.
In fact when you have an organization that large, it is going to use several languages, architectures, and technologies to make things happen.
Dessa forma fica bem mais organizado. Gostei.
How to create login form using MVC ?
Amazing bro! Most videos I saw were focusud on advanced. This is great for beginner!
Thank you!
my search is end here. now I can sleep well. Thank you very much sir. ♥️
Thank you bro.
Glad you liked it!
Impressive
Amazing
Thank you! Cheers!
Nice one bro!
where's the model part?
Models usually comes depending on your database, that's why I didn't include. But I plan on making an updated video on how to use the mvc pattern!
@@PedroTechnologies I will use postgres, I'm waiting, thanks!
Nice video man
great!
Thanks
God damn, the only tutorial which is explaining the structure with simple words, thanks !
Hugs from Brazil!!
Sou br também kkkkkkk Abraço
@@PedroTechnologies a não véi sksksksksksks eu meio que imaginei, vi que no tutorial de crud a localização era salvador, pqp, fala bem pra cacete inglês. Teu nome também kkkkkkkk
Can you show me how to get data from SQL using MVC pattern
Lets say that the name he displayed is inside a DB. The logic to get the name would be inside the Models folder. So the controller would make a request to a function in Models and the models would return the raw data from DB to controller, then the controler would process the data.
In this case you would like to have another folder called "config" and add all the parameters related to DB connection.
Great video! Simple, straight to the point and easy to understand.
Thank You Sir
This save my life!!! Thanks a lot man
Glad to hear that!
Excellent explanation ❤
Best tutorial. Thanks
thank you sir
I'm surpporting you in republic of korea
Simple but helped me a ton, thanks