Vanilla Node.js REST API | No Framework

Поделиться
HTML-код
  • Опубликовано: 24 июл 2024
  • Let's create a REST API using Node.js only, without Express
    Code:
    github.com/bradtraversy/vanil...
    💖 Support The Channel!
    / traversymedia
    Website & Brad Traversy Udemy Course Links:
    www.traversymedia.com
    Follow Traversy Media:
    / traversymedia
    / traversymedia
    / traversymedia
    Timestamps:
    0:00 - Intro
    2:03 - Getting Started
    3:06 - HTTP Create Server
    5:27 - Send a Simple Response
    10:43 - Simple Routing
    13:17 - Create The Model & Controller
    14:45 - Get All Products
    19:35 - Get Product By ID
    27:15 - Create Product
    39:17 - Getting Body Data
    48:38 - Updating Products
    56:36 - Deleting Products
  • НаукаНаука

Комментарии • 320

  • @TraversyMedia
    @TraversyMedia  3 года назад +191

    I realized I have never done this. In an actual project, you would most likely use Express or some other framework, but I wanted to do this for learning purposes so you can see a bit of what goes on under the hood. This API can be improved (eg. creating a better router), so feel free to work on it and make a PR :) Hope you enjoy!

    • @ammarrazzak5302
      @ammarrazzak5302 3 года назад +10

      I agree, creators like you will ensure that people learn the basics before moving on to the top layer and forgetting what was underneath all of it. I always schedule a coding session for myself of creating a mini express type clone with 'http" module, but never got to it. Thanks for the incredible content! Take care!

    • @codingman313
      @codingman313 3 года назад +9

      How is ur health now sir. In last few years i learnt a lot about web programming from ur channel. Thanks a lot for your sincere efforts for all these years helping numerous newcomers and students. I really felt bad when i found that your health was in bad condition. Seeing you active again really made me happy. Once again thank u so much from the bottom of my heart.

    • @cwinter90
      @cwinter90 3 года назад +3

      I actually was contacted by a company yesterday that was looking for someone with Node.js server experience. Told them I've used Express and NestJS figuring they were being generic. Nope... they legitimately use raw Node.js for their backend. Not interested in making things more difficult for myself lol.

    • @tomhames6884
      @tomhames6884 3 года назад +3

      Completely agree. Frameworks purposely abstract a lot of the details, but for beginners, and in general, it's really important to understand what's going on under the hood. Hope you're well, Brad.

    • @TraversyMedia
      @TraversyMedia  3 года назад +19

      @@codingman313 It is better. Still having the same issues, but I am on a new med that is helping. I will do an update on that soon :)

  • @codewithgedo3067
    @codewithgedo3067 3 года назад +110

    Your voice make me comfortable, and motivate me to listen to you even if I wouldn't 😂😂

  • @AbhaySharma-lf1cv
    @AbhaySharma-lf1cv 3 года назад +76

    Finally, The OG BRAD himself

    • @eleah2665
      @eleah2665 3 года назад +3

      the KING is here today.

  • @arkhamian7586
    @arkhamian7586 3 года назад +19

    You undoubtedly know how to push your audience towards developing real coding skills. Thank you in advance for all the hard work.

  • @FatherOfTheParty
    @FatherOfTheParty 3 года назад +1

    This was very instructive and well done. Thank you for taking the time to put this together! Going in I knew no NodeJS at all. Still far from fluent but I am now comfortable with the basics and can easily build on what you've taught me. Thanks again!

  • @peterluke9392
    @peterluke9392 3 года назад +1

    After watching your channel for a year or so, I decided to buy your js course. Worth every penny of it you helped me a ton.

  • @victorlima4801
    @victorlima4801 3 года назад

    A few days ago I decided to start making a mini express clone for self challenge and learning purposes, and now I found this. Your tutorial is extremely helpful, thanks a lot!

  • @mysterOrel7924
    @mysterOrel7924 3 года назад

    Already know all this but it's a good habit of mine to come back and watch tutos of things that i already know... sometimes you find yourself lreaning new things that you missed or forgot ! Thx Brad and happy to have you again !!!!

  • @abdullahalakus9700
    @abdullahalakus9700 3 года назад +7

    brad, you are the person who made me love the code, I can't thank you enough

  • @Pareshbpatel
    @Pareshbpatel 3 года назад +5

    Some serious learning that most newbies would not have bothered to learn. Thank you very much, Brad.
    [PBP 2021-05-25 20:48]

  • @denissanchezleyva8954
    @denissanchezleyva8954 3 года назад +2

    Hey Brad, you are like the Ave Fenix , after 30 days of break. Now, the contents is very high level. I am still in the last sections of your Mer-Ecommerce course after 3 weeks studying 2 hours per days. It is awesome. I recommend it 100%. And now this one. Man, you have a special skill to write code. It is like poetry for those who love coding. No doubt. God Bless you.

  • @tblancog
    @tblancog 3 года назад +1

    The most difficult part was to set the post data but certainly, all this makes you understand what's under the hood of a framework. Great tutorial, I enjoyed every minute.

  • @thesteppino45
    @thesteppino45 3 года назад

    Welcome back, Brad. You sealed the choice for me when I was trying to choose between starting web development and app development.
    Thanks.

  • @jordansumitomo2357
    @jordansumitomo2357 3 года назад +32

    Purchased your MERN ecommerce course learned a lot from you thank you keep making courses.

  • @dw.beastma9182
    @dw.beastma9182 3 года назад +1

    I just learned about fetching API today and now you posted about REST API using Node.js only!!!! Thanks for always sharing Brad, I bought your new course the day it's started being sold though haven't started learning it yet since I believe I should focus more on my foundation before tackling all the trending framework.

  • @nishantkumar6960
    @nishantkumar6960 3 года назад +2

    I work listening to Brad's voice and I sleep listening to Brad's voice 😁
    It keeps me calm.
    It's Brad 24*7✌️

  • @biswayannandi6136
    @biswayannandi6136 2 года назад +1

    There are many videos and blogs with titles 'REST API using NODE' and each one them are using Express. I wanted to learn how can I do it using Node only and I got this...Great work💕❤

  • @shaunr9088
    @shaunr9088 3 года назад

    List not only helped me understand REST better but Node JS in general. Thank you.

  • @vinubox
    @vinubox 3 года назад +2

    Ah! That soothing sound of information is a back, welcome back with all my heart...

  • @tobiasjennerjahn8659
    @tobiasjennerjahn8659 3 года назад +9

    Hopefully this video means you‘re doing well. Or at least a little better than before. Thanks for all the amazing content you put out.

  • @hsvt12
    @hsvt12 3 года назад

    this is amaing I love when people do videos which don't use libaries
    really shows the inner working of how the libary works

  • @fluntimes
    @fluntimes 3 года назад +1

    I have wanted to see this for a while just to be "in the know". I am doing your API Masterclass on Udemy and this tutorial outlines how cool Express is for handling all the moving parts of an API. Awesome!

  • @austinwheelo
    @austinwheelo 3 года назад

    With all due respect and props to your contributors, they did an excellent job, it is great to see you back! I hope you are doing well and feeling good! Pace yourself, we've all been there.

  • @latinrev3822
    @latinrev3822 3 года назад +3

    Really interesting seeing how the req.body works under the hood, really cool Brad!

  • @Mescudi94
    @Mescudi94 Год назад

    One of the best tutorial I have seen, thank you for this. Plus, you have a way to speak which is very comprehensible for non-english people like me, I'm quite amazed to understand very well each word !

  • @stuartmarsh5574
    @stuartmarsh5574 2 года назад

    Thank you, great video. It took me forever to realize that my delete response body wasn't showing up because I used a 204 response code. I like the idea of using a 200 and being able to confirm the deletion.

  • @LongBoy.0
    @LongBoy.0 3 года назад +1

    Brad, the MVP of software engineering out here doing on youtube what most $20,000 bootcamps claim to do, but fail at. Thanks so much Brad.

  • @KostasOreopoulos
    @KostasOreopoulos 3 года назад +1

    First of all, great video as always.
    A "quick" remark
    The View in MVC in the backend is not the "View - Presentation" of the results in your browser. View in MVC is the presentation of the Data to the outside world.
    In this case, the View is a Data-Mapper. You get data from the Database and create a "view" to send back. For example, you could create another View for a normal user (less data) and an admin (all data), or an authorized user (some data depending on authorization).
    Technically, not in this example, of course, The Model, should consist of a Service and a DAO (data access object).
    The controller gets the incoming data from the body and does validation of data and then "asks" the corresponding Service to do the task.
    The Service will reach out to different services (if needed, for example checking authorization, cache, external APIs, etc), prepare all the information, and then asks the DAO to get the data
    DAO is the data abstraction. For example, products could read data from JSON, XML, mongo, Postgres. DAO should be unified access. Let's say getProduct(id,'json'), if you want to define the source, but you could omit that. Just do getProduct(id), but hide which DB you are using. If you later want to change DB, you would just change the implementation of that function.
    A nice library doing that, which seems promising is prisma.io (currently only supporting SQL databases)

  • @sirojxujamuminkhodjaev1369
    @sirojxujamuminkhodjaev1369 3 года назад

    I entered the web development world with your help Brad. Nice to hear you again bro.

  • @cervantes01
    @cervantes01 3 года назад

    hi Brad, I've really been enjoying your guest contributors, but it is great that you can still post the occasional video. Well done:)

  • @CreativeJE
    @CreativeJE 3 года назад +1

    its so good to hear your voice brad I was really missing it :(

  • @rustatum2382
    @rustatum2382 3 года назад +5

    I found that uuid() would occasionally create an id number that begins with a letter instead of a number.
    It helps to replace the '[0-9]' with '[a-z0-9]' in the three url.match conditionals in the server component

    • @BigBaddaBoom
      @BigBaddaBoom 2 года назад +2

      Not all heroes wear capes, @RusTatum. Thank you. Unless, of course, maybe you are wearing a cape? I was troubleshooting why some uuids were breaking the getById function. If I could pin your comment to the top to help others, I would.
      I was receiving the response from the server of "Route Not Found" for UUIDs like: c69c7182-4a6d-4b78-aa03-e0db92cfe371
      Since this UUID started with a letter, everything broke.

  • @Judas_Is_Fish
    @Judas_Is_Fish 3 года назад

    You can't even imagine, how long I was waiting for this kind of video with vanilla Node.js. Thanks a lot, you make world a bit better :)

    • @Tim12x
      @Tim12x 3 года назад

      только вот для чего ты это ждал?

    • @Judas_Is_Fish
      @Judas_Is_Fish 3 года назад

      @@Tim12x Потому что мне грусто от того, что такие элементарные вещи, как обработка POST запроса, объясняют только на нагроможденном Express, а про ванильную ноду дальше запуска сервера почти никто ничего не объясняет

  • @jfbiswajit
    @jfbiswajit 3 года назад

    love to hear your voice after the intro. ah, peace!
    honestly, I can't tolerate anyone else voice after the intro. love you Brad! ❤

  • @jamjam3448
    @jamjam3448 2 года назад +1

    Thanks so much! I learned how the matching of the params work without expressjs

  • @emanueltejadacoste2250
    @emanueltejadacoste2250 3 года назад

    Amazing video, now i can move on to the node js complete course. you are a TITAN

  • @amarjitkumarsingh25
    @amarjitkumarsingh25 3 года назад

    Thanks Brad, it was a good learning curve. Enjoyed! Thanks for your time.

  • @_rachid
    @_rachid 3 года назад +1

    I loved this course, thank you Brad!

  • @tarunkishore4574
    @tarunkishore4574 3 года назад +1

    Man ! U always come to the rescue when i need something so badly !!

    • @tarunkishore4574
      @tarunkishore4574 3 года назад

      @Jack Saat I needed it to understand node completely. And currently facing some issues with express

  • @icaras12x87
    @icaras12x87 3 года назад

    Is it Brad? omg that's an honor. We subscribed because of you, Brad, never forget this

  • @jaychandran24
    @jaychandran24 3 года назад

    The MERN course is dope! Thanks, Brad!

  • @eyuelbegashaw8609
    @eyuelbegashaw8609 3 года назад +6

    please do more projects with pure NodeJS , no framework. there is literally nothing online except express. frameworks will change from time to time.
    we

  • @music-unleashed
    @music-unleashed 3 года назад +1

    I made API-s with PHP since the beginning of times but man... this was soo sweet.
    I have to mastering this stuff and search a new job :)

  • @SteveCarroll2011
    @SteveCarroll2011 3 года назад

    As someone that prefers minimal code when possible, this is most appreciated! The pacing is excellent, the sequence of how you put this together is, as well. No wasted time. It looks like you just turned on screencast recording and ‘winged’ it, is that the case?

  • @chinmayghule8272
    @chinmayghule8272 Год назад

    I followed through the entire course except for one thing. I used a regular array instead of a json file since I was using an old file from a previous tutorial. Because of this every time the server restarts all the changes made in the server got overridden and I had to start over again. Nice course, this really makes me appreciate Express.js.

  • @jaleotech5918
    @jaleotech5918 3 года назад

    Nice to have you back....thanks for the video

  • @user-ky7hv2mr7h
    @user-ky7hv2mr7h Год назад

    Incredible quality video! Good voice record and nice material!
    Thank you very much!

  • @Pareshbpatel
    @Pareshbpatel 2 года назад

    Completed excellent tutorial on CRUD API in Vanilla JS. Thanks, again, Brad
    {2021-12-16}

  • @regal_7877
    @regal_7877 3 года назад

    I've just got into backend web development (I'm an extreme newbie) and I've been searching to hell and back for this specific topic to no avail. I did a lot of reading and didn't want to learn a new language like Ruby and then Rails so this is such a blessing I can't even begin to describe. Thank you.

    • @BillClinton228
      @BillClinton228 3 года назад

      There are many ways to do backend work, Node is not the be all and end all just because all the "cool kids" are using it these days, 8 years ago Ruby was the in thing and all the hipster programmers couldnt shut up about it. Don't follow fads, try out different languages and use which ever language you feel most comfortable with, and if you think this tech will get you the most money remember this is the tech industry and fads change very quickly.

    • @regal_7877
      @regal_7877 3 года назад +1

      @@BillClinton228 Yeah definitely. I'm not one to get sucked into trends and stuff. I actually started off with C/C++ believe it or not, and I'm not even from a Computer Software background, I do Electronics. I'm still extremely inferior in those languages too but since then I've already tried python, java, html/css (not programming but close enough) and javascript. I just thought it would be easier to use Node.js since I've done some work with Node before. Although I do have a hard time wrapping my head around the "async-await-sync" stuff. I was actually already starting to learn Ruby but....time

  • @erikshumkov4848
    @erikshumkov4848 3 года назад

    Good to have you back again, hope you are doing well. :)

  • @stevenwinsir6229
    @stevenwinsir6229 3 года назад

    very helpful video, i always use koa framework and almost forget these basic node js. it seems like I need to review again

  • @88noname88
    @88noname88 3 года назад

    I'm so happy that we have frameworks like Express. It is makes our life easier

  • @lardosian
    @lardosian 3 года назад

    Thanks Brad, just watched an interesting video about serverless applications. Would love to hear your take on the serverless approach.

  • @Muaddibkhan
    @Muaddibkhan 3 года назад

    Great to see you brad back to your routine

  • @pratikxavier8176
    @pratikxavier8176 3 года назад +1

    After working with express for a while now I was still confused what's really happening under the hood. God bless you Brad🙂👍 #respect
    Love from India🙏

  • @KaranveerSingh97
    @KaranveerSingh97 2 года назад

    Nice video. To get params from urls, an easier way is to use the in-built url package in node.js

  • @sebastiancastillo3560
    @sebastiancastillo3560 3 года назад +1

    Yes !,
    finally our savior is back.
    Thank you Brad !, I hope you're great.

  • @darint07
    @darint07 3 года назад

    I was looking exactly for this. Thank you!

  • @cookiesndata211
    @cookiesndata211 2 года назад

    I enjoyed it ,thanks . Keep up great work. Have a Happy New year .

  • @excalibur885
    @excalibur885 3 года назад

    Best content on the internet xo happy that this channel exists. Ty Brad

  • @AslamD
    @AslamD 3 года назад +68

    This is how people are supposed to learn node instead of directly jumping on express.

    • @softwarelivre2389
      @softwarelivre2389 3 года назад

      That's more or less what I've attemped in Deno. Never tried it on Node, though.

    • @maxprofitonemilliongoal2184
      @maxprofitonemilliongoal2184 3 года назад

      6:10 BIG WIN 2020 ruclips.net/video/MNNd2DZSdKs/видео.html

    • @MrAfusensi
      @MrAfusensi 3 года назад +3

      It does not really matter. Once you get to the point of knowing express pretty well, the jump to the node js http API would not be very hard.

    • @_nom_
      @_nom_ 3 года назад

      No, I don't agree. What if you need to make it cors capable? Etc. Node is still providing a layer for you.

    • @MrAfusensi
      @MrAfusensi 3 года назад

      @@_nom_ When you learn either one you also learn development skills, which includes learning how to read and understand documentation.

  • @joshuataruc2385
    @joshuataruc2385 3 года назад

    Hi Brad Ive learned a lot from you this past 4years ive been watching your tutorials, will you please make a crash course of laravel 8 that will be much appreciated

  • @nested9301
    @nested9301 2 года назад

    i just complete all of this and i"m proud of my self xD thank you!

  • @mrjeter
    @mrjeter 3 года назад

    What a wonderful class, thanks Brad!

  • @maxd7228
    @maxd7228 3 года назад

    Ahhhh. The soothing sound of Brad’s keyboard.

  • @user-ru2jb4yo3s
    @user-ru2jb4yo3s 10 месяцев назад

    thank u sooooo much really worth and i made it with u step by step , it's fully functional at me

  • @prateekmitra9702
    @prateekmitra9702 3 года назад

    So that's what happens BTS Express.js. Really good explanation, given I am a newbie in backend.

  • @hamzaazr8181
    @hamzaazr8181 3 года назад

    listening to this voice made my day

  • @mackynikat8833
    @mackynikat8833 3 года назад

    . done with this . im only stuck with rest client but everything seems fine now . good luck adopting new era sir ( not on new normal )

  • @vishnujr1130
    @vishnujr1130 3 года назад +1

    Finished your MERN Ecommerce udemy course..it was a wonderful experience..learned a lot

    • @TraversyMedia
      @TraversyMedia  3 года назад +5

      Wow, that's impressive that you already finished it. It takes me a month to finish a 15 hour course lol

    • @ammarrazzak5302
      @ammarrazzak5302 3 года назад

      @@TraversyMedia Lol! Still working on the Modern JS course, has been over 1 year. Now it acts as a recipe book. But it helped me alot when I was struggling with JS.

    • @vishnujr1130
      @vishnujr1130 3 года назад

      @@TraversyMedia Thanks Brad. You did all the hardwork to get things easy for us. That's why I could finish the course much quicker. Your way of implementing redux in that course was impressive to me as a beginner. Thank you for all the hardwork and support.

  • @ThePurpleMaestro
    @ThePurpleMaestro 3 года назад

    i see video i hear brad's video i press like

  • @sakamoto399
    @sakamoto399 3 года назад

    glad to see you back.

  • @akramnarejo6221
    @akramnarejo6221 Год назад

    thanks for creating a beautiful content. and I happy to let you know that I completed it.

  • @rajsuthanofficial7585
    @rajsuthanofficial7585 3 года назад

    Hey Traversy, i don't know whether this a co-incident, but I did the exact same thing today for practice & wondered to make a video on this

  • @Saiphes
    @Saiphes 3 года назад

    YAY, I was your 3000th like for this video! :P

  • @FabioGiacomini
    @FabioGiacomini 8 месяцев назад

    Awesome video, very well explained. Thank you

  • @user-dx6we1pn6q
    @user-dx6we1pn6q 3 года назад

    I am a simple man. I hear Brad, I hit like

  • @Jet1323
    @Jet1323 3 года назад

    daim i love this video :O was about to look it up and there you were haha!!

  • @chukwumaobi7770
    @chukwumaobi7770 3 года назад

    Welcome back. we missed you!

  • @jakegerard1870
    @jakegerard1870 3 года назад

    Awesome stuff Brad!

  • @jemjem8902
    @jemjem8902 3 года назад

    How are you doin Brad? So happy seeing you again!

  • @justkitob
    @justkitob 3 года назад

    Yeah I hope come back Brad . the best tutor

  • @CodestarTechnologies
    @CodestarTechnologies 3 года назад

    This is what I was waiting for thanks brad

  • @sumukhakb2701
    @sumukhakb2701 3 года назад

    Awesome tutorial Brad. Please make on video on Redux thunk with react hooks

  • @junaidTni
    @junaidTni 3 года назад

    Hello sir. Thank you so much for efforts. Please also make node.js microservices with docker and kubernetes. Learning much more from you.

  • @jlambert12013
    @jlambert12013 2 года назад

    When Brad said “ it’s a pain in the ass (but) I like doing this kind of stuff” .. I felt that. @12:40

  • @eajajulratan2004
    @eajajulratan2004 3 года назад

    Thanks man!
    Good to see you!

  • @asdfkj123
    @asdfkj123 Год назад

    can you please explain why we did chunk.toString() in the getPostData function ?

  • @samirsamir7779
    @samirsamir7779 3 года назад

    Brad please , is there any chance to teach us really "how to master the shopify theme's building and customization" , really there is definitly no good video with this topic at all , your way to explain new things is just perfect , especially when you code directly live ! your udemy courses also helped me a lot ! thank you for your phenomenal channel Brad !

  • @maciekjedlinski1832
    @maciekjedlinski1832 3 года назад

    Just when I needed such video!

  • @Chandasouk
    @Chandasouk 3 года назад +1

    Brad is back!

  • @NeverCodeAlone
    @NeverCodeAlone 3 года назад

    Thx for this nice video. It brings me a lot because it is real know how and not only a framework configuration ;)

  • @mladjo2505
    @mladjo2505 3 года назад

    One minor note: The url.match part should match the id as the uuid v4 generates it (as /[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/ or maybe /[0-9a-f]+(-[0-9a-f]+)*/ for simplicity). You got lucky that the uuid v4 didn't generate any uuids starting with a-f as first character.
    Other than that really great stuff.

  • @DrLouellLSala
    @DrLouellLSala 3 года назад

    I've been looking for this topic

  • @laikesagores3258
    @laikesagores3258 2 года назад

    Great video, very helpfull, understanding. Thank you!!!

  • @asdfkj123
    @asdfkj123 Год назад

    When using " writeDataToFile("./data/products.json", products) " in productModel, why do we only put 1 dot before /data, and not 2 dots ? don't we need 2 dots to go outside the models folder?

  • @asdfkj123
    @asdfkj123 Год назад

    at 40:20, where in the documentation can i find this ? tried to search on my own but couldnt find anything. thank you.

  • @zeeshanmh215
    @zeeshanmh215 3 года назад

    Do you have a tutorial on working with vs code and pushing changes to GitHub and deploying the site into vercel (or any others)?

  • @primatondyaryakurniawan267
    @primatondyaryakurniawan267 3 года назад

    Wow, i realize we should respect a framework for making it lot easier

  • @arunarkamukhopadhyay6443
    @arunarkamukhopadhyay6443 3 года назад

    Finally Brad is back.