Learn MVC Pattern with ExpressJS and NodeJS - Tutorial Beginner

  Рет қаралды 91,296

PedroTech

PedroTech

Күн бұрын

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

Пікірлер: 102
@codecraftwebdevelopment
@codecraftwebdevelopment 4 ай бұрын
I really loved that you didn't cut out that part where the error happened. Shows the realities of coding.
@tesla1772
@tesla1772 3 жыл бұрын
would love to see a full project made in mvc pattern
@andre-SJP-PR
@andre-SJP-PR Жыл бұрын
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.
@joeangello2016
@joeangello2016 9 ай бұрын
That's just you, everyone learns differently, because I am a beginner and loved his explanation.
@CodingByAmp
@CodingByAmp 2 жыл бұрын
teach smooth and easy intesting
@Liam-c5k
@Liam-c5k 25 күн бұрын
Helpful video! Here from The Odin Project :)
@karlasosa5304
@karlasosa5304 3 жыл бұрын
Amazing video! can you please make one where you explain it in more detail? Thanks!!
@PedroTechnologies
@PedroTechnologies 3 жыл бұрын
Yes! I've been planning on doing an update!
@iNovotek
@iNovotek 3 жыл бұрын
Recommended kzbin.info/www/bejne/d2moo2OJec-jb7s
@joeangello2016
@joeangello2016 9 ай бұрын
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!!
@kinstar
@kinstar 2 жыл бұрын
The whole require thing really threw me off for abit being so used to import 😂🤦‍♂️
@porobertdev
@porobertdev Күн бұрын
Thanks for the explanation. I'm here from The Odin Project. Good luck odinators! I don't think many made it to the backend section. Keep going! 👏
@RangelGSousa
@RangelGSousa 3 жыл бұрын
Kkkk eu acompanhando o vídeo e me perguntando que espécie de americano tem o nome de Pedro Machado... Kk
@SVGPRO
@SVGPRO Жыл бұрын
I understood the concept. Just use the word "basically" less next time.
@bahernandes1
@bahernandes1 3 жыл бұрын
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.
@PedroTechnologies
@PedroTechnologies 3 жыл бұрын
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!
@bahernandes1
@bahernandes1 3 жыл бұрын
Ok, thanks! I will watch this video.
@shreerambhaktisagar-adhyat6009
@shreerambhaktisagar-adhyat6009 2 жыл бұрын
Hello sir Kindly make a video on crud operation using this MVC pattern
@riimkahack2951
@riimkahack2951 5 ай бұрын
sorry but i don"t like your explanation, i expected at least an example ...
@gabrielfigueiredo7344
@gabrielfigueiredo7344 4 ай бұрын
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!
@marsdwarf
@marsdwarf 2 жыл бұрын
Thanks for the video :) Question: What code goes in the models folder?
@tharindumadhushan7776
@tharindumadhushan7776 Жыл бұрын
Data
@MrBond00Seven
@MrBond00Seven Жыл бұрын
Database collection schemas and models
@FilthySnob
@FilthySnob 11 ай бұрын
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?
@TPGamingFX
@TPGamingFX 16 күн бұрын
How many came here from Odin Project?
@f3-faithfitnessfinance
@f3-faithfitnessfinance 4 жыл бұрын
Perdo ..your latest video is private🤔
@PedroTechnologies
@PedroTechnologies 4 жыл бұрын
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!
@f3-faithfitnessfinance
@f3-faithfitnessfinance 4 жыл бұрын
@@PedroTechnologies oh...coool
@jeremyolu2787
@jeremyolu2787 9 ай бұрын
router has been depreciated in new version of express
@Rakibul-Hasan-Mahin
@Rakibul-Hasan-Mahin 3 жыл бұрын
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.
@LorenzoJimenez
@LorenzoJimenez Жыл бұрын
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
@spounka
@spounka Жыл бұрын
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
@nathansantos4197
@nathansantos4197 2 жыл бұрын
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!
@pranavbaradkar5763
@pranavbaradkar5763 Жыл бұрын
Same here bro!
@hyperkon9807
@hyperkon9807 Жыл бұрын
good explanation
@umaranisaravanan4336
@umaranisaravanan4336 5 ай бұрын
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
@MichaelGuy
@MichaelGuy 3 жыл бұрын
I have been told not to run mvc on node. there is and equivalent for node.
@PedroTechnologies
@PedroTechnologies 3 жыл бұрын
Interesting, why would you not be able to use node? You can use other backend languages and frameworks like python / flask or golang.
@MichaelGuy
@MichaelGuy 3 жыл бұрын
@@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.
@PedroTechnologies
@PedroTechnologies 3 жыл бұрын
@@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).
@MichaelGuy
@MichaelGuy 3 жыл бұрын
@@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.
@ramya..6902
@ramya..6902 Жыл бұрын
Hi ,where to mention module.exports=get
@ndhumal41
@ndhumal41 Жыл бұрын
Why model not created
@Sundarkarthik-h3i
@Sundarkarthik-h3i Жыл бұрын
what about model?
@Hardwell18
@Hardwell18 2 жыл бұрын
How to create login form using MVC ?
@kelas-frontend
@kelas-frontend 3 жыл бұрын
Thanks, can you explain how to work with models too? In this you just explain the controller.
@PedroTechnologies
@PedroTechnologies 3 жыл бұрын
Yeah, i mad this video a while ago and I din't go too much in depth, but I plan on making another one!
@kelas-frontend
@kelas-frontend 3 жыл бұрын
@@PedroTechnologies can't wait 👍😁
@ajiteshsivakumar
@ajiteshsivakumar 2 жыл бұрын
@@PedroTechnologies Is it out yet ?
@samiran__roy
@samiran__roy 2 жыл бұрын
my search is end here. now I can sleep well. Thank you very much sir. ♥️
@the_oneironaut
@the_oneironaut 4 ай бұрын
Dessa forma fica bem mais organizado. Gostei.
@tedmosby1900
@tedmosby1900 4 жыл бұрын
Amazing bro! Most videos I saw were focusud on advanced. This is great for beginner!
@PedroTechnologies
@PedroTechnologies 4 жыл бұрын
Thank you!
@mouhannadal-hmedi1501
@mouhannadal-hmedi1501 Жыл бұрын
thanks
@jellyfish1772
@jellyfish1772 Жыл бұрын
thanks
@lipo971
@lipo971 3 жыл бұрын
salve pedro, teu inglês é mt bom
@PedroTechnologies
@PedroTechnologies 3 жыл бұрын
Vlww mano kkkkkk
@lipo971
@lipo971 3 жыл бұрын
@@PedroTechnologies é nós, me ajudou numa prova q eu to fazendo pra uma vaga kkkkkkk vlw maninho
@coco5843
@coco5843 3 жыл бұрын
God damn, the only tutorial which is explaining the structure with simple words, thanks !
@thiagocristianotavares7603
@thiagocristianotavares7603 3 жыл бұрын
where's the model part?
@PedroTechnologies
@PedroTechnologies 3 жыл бұрын
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!
@thiagocristianotavares7603
@thiagocristianotavares7603 3 жыл бұрын
@@PedroTechnologies I will use postgres, I'm waiting, thanks!
@xx-fw1yq
@xx-fw1yq 3 жыл бұрын
Nice video 😁
@PedroTechnologies
@PedroTechnologies 3 жыл бұрын
Thanks 😁
@akashchauhan6784
@akashchauhan6784 4 жыл бұрын
❤️❤️❤️
@WTFIAMTKL
@WTFIAMTKL 3 жыл бұрын
Thank you bro.
@PedroTechnologies
@PedroTechnologies 3 жыл бұрын
Glad you liked it!
@fabianoone
@fabianoone 3 жыл бұрын
Nice & easy explanation
@PedroTechnologies
@PedroTechnologies 3 жыл бұрын
Thank you!
@alirezakhaki9340
@alirezakhaki9340 3 жыл бұрын
Amazing
@PedroTechnologies
@PedroTechnologies 3 жыл бұрын
Thank you! Cheers!
@iamrichid
@iamrichid 7 ай бұрын
Impressive
@tiagon14
@tiagon14 2 жыл бұрын
Thanks
@NormelAlmagro
@NormelAlmagro 7 ай бұрын
Nice one bro!
@Deanahasina
@Deanahasina Жыл бұрын
Nice video man
@sabujdeeptudu6215
@sabujdeeptudu6215 Жыл бұрын
great!
@mooder3247
@mooder3247 4 жыл бұрын
😍😍🤗
@Ash-fh3mh
@Ash-fh3mh 2 жыл бұрын
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. 😅
@karangovindaraj8844
@karangovindaraj8844 3 жыл бұрын
Can you show me how to get data from SQL using MVC pattern
@alexdominguess
@alexdominguess 4 ай бұрын
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.
@gustavonoronha3586
@gustavonoronha3586 4 жыл бұрын
Hugs from Brazil!!
@PedroTechnologies
@PedroTechnologies 4 жыл бұрын
Sou br também kkkkkkk Abraço
@gustavonoronha3586
@gustavonoronha3586 4 жыл бұрын
@@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
@calebmorsecode
@calebmorsecode Жыл бұрын
Great video! Simple, straight to the point and easy to understand.
@ajaychawda682
@ajaychawda682 4 жыл бұрын
Thank you so much bro ❤️
@PedroTechnologies
@PedroTechnologies 4 жыл бұрын
Than you for watching!
@ajaychawda682
@ajaychawda682 4 жыл бұрын
@@PedroTechnologies I have doubt about the model, can you give example for any random query?
@PedroTechnologies
@PedroTechnologies 4 жыл бұрын
@@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 )
@ajaychawda682
@ajaychawda682 4 жыл бұрын
@@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
@PedroTechnologies
@PedroTechnologies 4 жыл бұрын
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
@ivancordoba378
@ivancordoba378 3 жыл бұрын
This save my life!!! Thanks a lot man
@PedroTechnologies
@PedroTechnologies 3 жыл бұрын
Glad to hear that!
@꼬꾸마-z9f
@꼬꾸마-z9f 2 жыл бұрын
thank you!!@@ Thanks to your video, i could understand easily what mvc is
@sonusinghstyle990
@sonusinghstyle990 Жыл бұрын
Thank You Sir
@AAfzal-lk2nf
@AAfzal-lk2nf 6 ай бұрын
Your videos are really simple and to the point, it's really easy to understand👍🏻
@김건우-n8d1d
@김건우-n8d1d Жыл бұрын
thank you sir I'm surpporting you in republic of korea
@zarghamaijaz5933
@zarghamaijaz5933 Жыл бұрын
Best tutorial. Thanks
@mumk
@mumk Жыл бұрын
Simple but helped me a ton, thanks
@JohnWickXD
@JohnWickXD Жыл бұрын
Excellent explanation ❤
@arulrino7958
@arulrino7958 7 ай бұрын
simply brilliant !!
MVC Pattern Explained Easy | MVC Tutorial (Example in NodeJS)
17:05
How To Get Married:   #short
00:22
Jin and Hattie
Рет қаралды 24 МЛН
Brawl Stars Edit😈📕
00:15
Kan Andrey
Рет қаралды 59 МЛН
Learn Express Middleware In 14 Minutes
14:48
Web Dev Simplified
Рет қаралды 399 М.
What Is MVC? Simple Explanation
10:40
Traversy Media
Рет қаралды 515 М.
How to build a REST API with Node js & Express
58:40
Programming with Mosh
Рет қаралды 1,7 МЛН
Node.js Crash Course Tutorial #11 - Express Router & MVC
22:29
Net Ninja
Рет қаралды 218 М.
Node.js Project Structure and Architecture Best Practices
7:38
Software Developer Diaries
Рет қаралды 33 М.
How to Use Model-View-Controller (MVC) in Node.js
10:57
Gravity
Рет қаралды 18 М.