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 Наука
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!
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!
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.
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.
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.
@@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 :)
Your voice make me comfortable, and motivate me to listen to you even if I wouldn't 😂😂
Thanks :)
Actually you make me feel that there is still more I can do. Thanks for all your contributions and support.
Yes really
Yeah, You are right.
yeah me to
Finally, The OG BRAD himself
the KING is here today.
You undoubtedly know how to push your audience towards developing real coding skills. Thank you in advance for all the hard work.
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!
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.
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!
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 !!!!
brad, you are the person who made me love the code, I can't thank you enough
Some serious learning that most newbies would not have bothered to learn. Thank you very much, Brad.
[PBP 2021-05-25 20:48]
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.
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.
Welcome back, Brad. You sealed the choice for me when I was trying to choose between starting web development and app development.
Thanks.
Purchased your MERN ecommerce course learned a lot from you thank you keep making courses.
Where is the course
@@vinukapussepitiya3939 www.udemy.com/course/mern-ecommerce/
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.
I work listening to Brad's voice and I sleep listening to Brad's voice 😁
It keeps me calm.
It's Brad 24*7✌️
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💕❤
List not only helped me understand REST better but Node JS in general. Thank you.
Ah! That soothing sound of information is a back, welcome back with all my heart...
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.
this is amaing I love when people do videos which don't use libaries
really shows the inner working of how the libary works
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!
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.
Really interesting seeing how the req.body works under the hood, really cool Brad!
7:50 BIG WIN 2020 ruclips.net/video/DgK8LO1EyWg/видео.html
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 !
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.
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.
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)
I entered the web development world with your help Brad. Nice to hear you again bro.
hi Brad, I've really been enjoying your guest contributors, but it is great that you can still post the occasional video. Well done:)
its so good to hear your voice brad I was really missing it :(
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
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.
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 Потому что мне грусто от того, что такие элементарные вещи, как обработка POST запроса, объясняют только на нагроможденном Express, а про ванильную ноду дальше запуска сервера почти никто ничего не объясняет
love to hear your voice after the intro. ah, peace!
honestly, I can't tolerate anyone else voice after the intro. love you Brad! ❤
Thanks so much! I learned how the matching of the params work without expressjs
Amazing video, now i can move on to the node js complete course. you are a TITAN
Thanks Brad, it was a good learning curve. Enjoyed! Thanks for your time.
I loved this course, thank you Brad!
Man ! U always come to the rescue when i need something so badly !!
@Jack Saat I needed it to understand node completely. And currently facing some issues with express
Is it Brad? omg that's an honor. We subscribed because of you, Brad, never forget this
The MERN course is dope! Thanks, Brad!
please do more projects with pure NodeJS , no framework. there is literally nothing online except express. frameworks will change from time to time.
we
true
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 :)
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?
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.
Nice to have you back....thanks for the video
Incredible quality video! Good voice record and nice material!
Thank you very much!
Completed excellent tutorial on CRUD API in Vanilla JS. Thanks, again, Brad
{2021-12-16}
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.
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.
@@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
Good to have you back again, hope you are doing well. :)
very helpful video, i always use koa framework and almost forget these basic node js. it seems like I need to review again
I'm so happy that we have frameworks like Express. It is makes our life easier
Thanks Brad, just watched an interesting video about serverless applications. Would love to hear your take on the serverless approach.
Great to see you brad back to your routine
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🙏
Nice video. To get params from urls, an easier way is to use the in-built url package in node.js
Yes !,
finally our savior is back.
Thank you Brad !, I hope you're great.
I was looking exactly for this. Thank you!
I enjoyed it ,thanks . Keep up great work. Have a Happy New year .
Best content on the internet xo happy that this channel exists. Ty Brad
This is how people are supposed to learn node instead of directly jumping on express.
That's more or less what I've attemped in Deno. Never tried it on Node, though.
6:10 BIG WIN 2020 ruclips.net/video/MNNd2DZSdKs/видео.html
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.
No, I don't agree. What if you need to make it cors capable? Etc. Node is still providing a layer for you.
@@_nom_ When you learn either one you also learn development skills, which includes learning how to read and understand documentation.
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
i just complete all of this and i"m proud of my self xD thank you!
What a wonderful class, thanks Brad!
Ahhhh. The soothing sound of Brad’s keyboard.
thank u sooooo much really worth and i made it with u step by step , it's fully functional at me
So that's what happens BTS Express.js. Really good explanation, given I am a newbie in backend.
listening to this voice made my day
. done with this . im only stuck with rest client but everything seems fine now . good luck adopting new era sir ( not on new normal )
Finished your MERN Ecommerce udemy course..it was a wonderful experience..learned a lot
Wow, that's impressive that you already finished it. It takes me a month to finish a 15 hour course lol
@@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.
@@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.
i see video i hear brad's video i press like
glad to see you back.
thanks for creating a beautiful content. and I happy to let you know that I completed it.
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
YAY, I was your 3000th like for this video! :P
Awesome video, very well explained. Thank you
I am a simple man. I hear Brad, I hit like
daim i love this video :O was about to look it up and there you were haha!!
Welcome back. we missed you!
Awesome stuff Brad!
How are you doin Brad? So happy seeing you again!
Yeah I hope come back Brad . the best tutor
This is what I was waiting for thanks brad
Awesome tutorial Brad. Please make on video on Redux thunk with react hooks
Hello sir. Thank you so much for efforts. Please also make node.js microservices with docker and kubernetes. Learning much more from you.
When Brad said “ it’s a pain in the ass (but) I like doing this kind of stuff” .. I felt that. @12:40
Thanks man!
Good to see you!
can you please explain why we did chunk.toString() in the getPostData function ?
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 !
Just when I needed such video!
Brad is back!
Thx for this nice video. It brings me a lot because it is real know how and not only a framework configuration ;)
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.
I've been looking for this topic
Great video, very helpfull, understanding. Thank you!!!
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?
at 40:20, where in the documentation can i find this ? tried to search on my own but couldnt find anything. thank you.
Do you have a tutorial on working with vs code and pushing changes to GitHub and deploying the site into vercel (or any others)?
Wow, i realize we should respect a framework for making it lot easier
Finally Brad is back.