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

КОМЕНТАРІ • 101

  • @codecraftwd
    @codecraftwd 4 місяці тому +9

    I really loved that you didn't cut out that part where the error happened. Shows the realities of coding.

  • @AAfzal-lk2nf
    @AAfzal-lk2nf 6 місяців тому

    Your videos are really simple and to the point, it's really easy to understand👍🏻

  • @Ash-fh3mh
    @Ash-fh3mh 2 роки тому +1

    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. 😅

  • @fabianoone
    @fabianoone 3 роки тому +1

    Nice & easy explanation

  • @hyperkon9807
    @hyperkon9807 Рік тому +1

    good explanation

  • @arulrino7958
    @arulrino7958 6 місяців тому

    simply brilliant !!

  • @marsdwarf
    @marsdwarf 2 роки тому +3

    Thanks for the video :) Question: What code goes in the models folder?

  • @SVGPRO
    @SVGPRO Рік тому

    I understood the concept. Just use the word "basically" less next time.

  • @xx-fw1yq
    @xx-fw1yq 3 роки тому +1

    Nice video 😁

  • @꼬꾸마-z9f
    @꼬꾸마-z9f 2 роки тому

    thank you!!@@ Thanks to your video, i could understand easily what mvc is

  • @ramya..6902
    @ramya..6902 Рік тому

    Hi ,where to mention module.exports=get

  • @lipo971
    @lipo971 3 роки тому +1

    salve pedro, teu inglês é mt bom

    • @PedroTechnologies
      @PedroTechnologies  3 роки тому +3

      Vlww mano kkkkkk

    • @lipo971
      @lipo971 3 роки тому +1

      @@PedroTechnologies é nós, me ajudou numa prova q eu to fazendo pra uma vaga kkkkkkk vlw maninho

  • @ajaychawda682
    @ajaychawda682 3 роки тому +1

    Thank you so much bro ❤️

    • @PedroTechnologies
      @PedroTechnologies  3 роки тому

      Than you for watching!

    • @ajaychawda682
      @ajaychawda682 3 роки тому +1

      @@PedroTechnologies I have doubt about the model, can you give example for any random query?

    • @PedroTechnologies
      @PedroTechnologies  3 роки тому

      @@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 3 роки тому +1

      @@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  3 роки тому

      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

  • @mooder3247
    @mooder3247 3 роки тому +1

    😍😍🤗

  • @tesla1772
    @tesla1772 3 роки тому +29

    would love to see a full project made in mvc pattern

  • @andre-SJP-PR
    @andre-SJP-PR Рік тому +4

    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 місяців тому +3

      That's just you, everyone learns differently, because I am a beginner and loved his explanation.

  • @Liam-c5k
    @Liam-c5k 22 дні тому +1

    Helpful video! Here from The Odin Project :)

  • @CodingByAmp
    @CodingByAmp 2 роки тому +2

    teach smooth and easy intesting

  • @umaranisaravanan4336
    @umaranisaravanan4336 4 місяці тому

    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

  • @karlasosa5304
    @karlasosa5304 3 роки тому +7

    Amazing video! can you please make one where you explain it in more detail? Thanks!!

    • @PedroTechnologies
      @PedroTechnologies  3 роки тому +1

      Yes! I've been planning on doing an update!

    • @iNovotek
      @iNovotek 3 роки тому

      Recommended ua-cam.com/video/A8Er0SDjp9Y/v-deo.html

  • @joeangello2016
    @joeangello2016 9 місяців тому +6

    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 роки тому +1

    The whole require thing really threw me off for abit being so used to import 😂🤦‍♂️

  • @RangelGSousa
    @RangelGSousa 3 роки тому +2

    Kkkk eu acompanhando o vídeo e me perguntando que espécie de americano tem o nome de Pedro Machado... Kk

  • @riimkahack2951
    @riimkahack2951 4 місяці тому

    sorry but i don"t like your explanation, i expected at least an example ...

  • @bahernandes1
    @bahernandes1 3 роки тому +2

    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 роки тому +1

      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.

  • @TPGamingFX
    @TPGamingFX 13 днів тому

    How many came here from Odin Project?

  • @jeremyolu2787
    @jeremyolu2787 9 місяців тому

    router has been depreciated in new version of express

  • @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!

  • @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?

  • @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

  • @f3-faithfitnessfinance
    @f3-faithfitnessfinance 3 роки тому +1

    Perdo ..your latest video is private🤔

    • @PedroTechnologies
      @PedroTechnologies  3 роки тому

      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 3 роки тому +1

      @@PedroTechnologies oh...coool

  • @nathansantos4197
    @nathansantos4197 2 роки тому +4

    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!

  • @Sundarkarthik-h3i
    @Sundarkarthik-h3i Рік тому

    what about model?

  • @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.

  • @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

  • @shreerambhaktisagar-adhyat6009
    @shreerambhaktisagar-adhyat6009 2 роки тому

    Hello sir
    Kindly make a video on crud operation using this MVC pattern

  • @kelas-frontend
    @kelas-frontend 3 роки тому +1

    Thanks, can you explain how to work with models too? In this you just explain the controller.

    • @PedroTechnologies
      @PedroTechnologies  3 роки тому +1

      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 роки тому +1

      @@PedroTechnologies Is it out yet ?

  • @mouhannadal-hmedi1501
    @mouhannadal-hmedi1501 Рік тому

    thanks

  • @jellyfish1772
    @jellyfish1772 Рік тому

    thanks

  • @ndhumal41
    @ndhumal41 Рік тому

    Why model not created

  • @akashchauhan6784
    @akashchauhan6784 3 роки тому +1

    ❤️❤️❤️

  • @MichaelGuy
    @MichaelGuy 3 роки тому +1

    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 роки тому +1

      @@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.

  • @the_oneironaut
    @the_oneironaut 3 місяці тому

    Dessa forma fica bem mais organizado. Gostei.

  • @Hardwell18
    @Hardwell18 2 роки тому

    How to create login form using MVC ?

  • @tedmosby1900
    @tedmosby1900 3 роки тому +3

    Amazing bro! Most videos I saw were focusud on advanced. This is great for beginner!

  • @samiran__roy
    @samiran__roy 2 роки тому +2

    my search is end here. now I can sleep well. Thank you very much sir. ♥️

  • @WTFIAMTKL
    @WTFIAMTKL 3 роки тому +1

    Thank you bro.

  • @iamrichid
    @iamrichid 7 місяців тому

    Impressive

  • @alirezakhaki9340
    @alirezakhaki9340 3 роки тому +1

    Amazing

  • @NormelAlmagro
    @NormelAlmagro 7 місяців тому

    Nice one bro!

  • @thiagocristianotavares7603
    @thiagocristianotavares7603 3 роки тому +1

    where's the model part?

    • @PedroTechnologies
      @PedroTechnologies  3 роки тому +1

      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!

  • @Deanahasina
    @Deanahasina Рік тому

    Nice video man

  • @sabujdeeptudu6215
    @sabujdeeptudu6215 Рік тому

    great!

  • @tiagon14
    @tiagon14 2 роки тому

    Thanks

  • @coco5843
    @coco5843 3 роки тому +1

    God damn, the only tutorial which is explaining the structure with simple words, thanks !

  • @gustavonoronha3586
    @gustavonoronha3586 3 роки тому +1

    Hugs from Brazil!!

    • @PedroTechnologies
      @PedroTechnologies  3 роки тому +3

      Sou br também kkkkkkk Abraço

    • @gustavonoronha3586
      @gustavonoronha3586 3 роки тому

      @@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

  • @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.

  • @calebmorsecode
    @calebmorsecode Рік тому +1

    Great video! Simple, straight to the point and easy to understand.

  • @sonusinghstyle990
    @sonusinghstyle990 Рік тому

    Thank You Sir

  • @ivancordoba378
    @ivancordoba378 3 роки тому +1

    This save my life!!! Thanks a lot man

  • @JohnWickXD
    @JohnWickXD Рік тому

    Excellent explanation ❤

  • @zarghamaijaz5933
    @zarghamaijaz5933 Рік тому

    Best tutorial. Thanks

  • @김건우-n8d1d
    @김건우-n8d1d Рік тому

    thank you sir
    I'm surpporting you in republic of korea

  • @mumk
    @mumk Рік тому

    Simple but helped me a ton, thanks