Handling Errors & Improving the Project Setup | Creating a REST API with Node.js
Vložit
- čas přidán 4. 12. 2017
- Things can go wrong in our Node RESTful API. Time to add some proper error handling. And let's also improve our workflow, so that we don't constantly have to restart the server.
----------
Learn Node.js in our comprehensive 30h+ course: acad.link/nodejs
Nodemon: github.com/remy/nodemon
Source Code: github.com/academind/node-res...
----------
• You can follow Max on Twitter (@maxedapps).
• You can also find us on Facebook.( / academindchannel )
• Or visit our Website (www.academind.com) and subscribe to our newsletter!
See you in the videos!
4 videos in and I just realized that there are no ads. Sir, I hope you get all the recognition you deserve!
Thank you for making this series, I appreciate the help!
Thank YOU for your awesome feedback Derek!
Even when you are wrong, things works as expected. Great guy hahaha
That is actually a build up to a bigger punch in the face
Thanks max always improves my coding with your tutorials. ❤️
Your courses and videos are just amazing!
This was very helpful. You are awesome. Keep making more videos like this!!
I will, thanks for your awesome feedback!
Maaaaaaaan. This is great! Insanely helpfull, easy to understand, actually fun to follow!
You are the best instructor on Udemy. I really enjoy your teaching method.
this video helped me a lot. A lot of people made videos were I had to have 600 lines of copy pastaed app.get and app.post on index.js, now I have like 90 lines.
Fantastic tutorial series so far. Thank you.
Very happy to read that you like it Keren, thanks a lot!
Finally i know what is RESTful API and the function . Thanks. Subscribed
Thank you Syahrizal, great to have you on board of the channel!
Looking forward to see your new react native course on udemy. I am just finishing the typescript one this week. In fact, I am refactoring this series in typescript while I keep up with you. It's pretty amazing the IDE support, code completion and how VSCode is able to catch error on the spot when using typescript. Great video as always! Thanks for your great work!
So happy to have you on board of the courses on Udemy and here on CZcams Wéder, thank you very much for your support!
I did this whole tutorial about 3 years ago, still refer to it on occasion, as I am now. Love Max and Manu! ❤
but Manchester united is shit now
but Manchester united is crap now.
-
-
wait they were craap 3 years ago too
one of the best serious on apis.... nice serious thanks
I like all your cources, good job :)
That's so awesome to read, thanks a lot!
Very happy with all videos
I've finished a couple of Max's courses on Udemy, too. As always, great material, great teaching. Thanx, Max!
That's just fantastic to read Sharis, thanks a lot for your awesome feedback!
Awesome video. Just found your channel today and immediately subscribed.
So happy to have you on board Meyyappan, thank you for your support!
Keep it up man! Best channel for nodejs/express!!!
Thanks for your great feedback Nikola, I'll try my best to keep it up :)
Thank you! :)
Wonderful explanation! nice and simple but more beneficial!
Thanks a lot Fawad!
Thanks . Your videos are great!
Great teacher and I love your accent, sounds to me like you're saying serious and wizard instead of series and visit haha, I understand you very well though and you have good English though I guess it's not your first language :). Very informative videos!
Very well explained. I think is very clear and understandable.
That's really great to read Josue, thank you very much for your support!
Helped me understand my work's code better. Thank you!
Although I do not know English I follow you because your channel is beautiful && Thanks
Great content as always!
Thank you so much Jaime!
So much fun and so much help.
Happy to read that, thank you Jesse!
Thanks Max!
Again and again Bro you are great did well.. very good explanation.... love you brother. :)
Excellent tutorials
not even a single downvote. that explain everyone love this course. Fantastic tutorial. i love learning Node now.
It's so great to get such a wonderful feedback from you and all the others here on the channel, thanks so much Karthikeyan!
Awesome! Keep on going :)
Videos will keep coming - thanks for your great feedback! :)
This is great!, but I think we should check the caught error cuz some errors should not be returned to the client
Great tutorial :)
Great tutorials as always.
good
Thank you for this awesome video
Thank YOU for your comment Abhishek :)
couldnt you make nodemon global by using the -g tag when installing?
Really good tuts series
So great to read that, thank you Max!
M8 thank you: i tried to find this kind of tutorial on other channels and on Pluralsight, and this one is most suitable for some one that wants to code along and understand some best practices. Keep up with a good work.
SPEECHLESS 👌👌
Aulas ótimas, salvou !!
very good keep going
Great video! please can you make a video on api units test endpoins using mocha or jasmine?
I like it, Sir.
So here instead of manually handling errors in try-catch blocks for every route we just define a middleware that handles all the errors and returns the result?
Really love your videos! However I noticed that the middleware handling 404 Error also handles other errors like invalid http methods, .... I wonder if there is anyway to prevent that? (just handle 404 error only).
Excellent tutorial, congratulations.
We had problems to run the nodemon but resolved to reinstall the express.
Scenario: [nodemon] starting `node server.js`
module.js: 549
throw err;
^
Error: Can not find module 'express'
Soluction: $ npm install express
Best Regards,
so is it better to download as global instead or type individually? I love the detailed videos. Thank you for teaching us! XD
amazing!!!!!
Great tutorials. :)
Thank you Amit :)
When you'll upload next one?
Why is morgan response time different than the one in postman?
nice video!!
Thanks! Happy to hear you're enjoying it!
Welcome to this "SERIOUS" ! :)
:D
Hey great explaination I just have one doubt wouldnt the error handler middleware executes for every request for ok as well as bad ones ?
the ok requests are consumed by /products and /orders and returned. so they do not trickle down to the end
Quick note to all viewers from more recent and upwards versions, If you dont change your "main": to be "main": "server.js" Nodemon will throw an error because it will try and search for the default "index.js" which is not in our file (In case you plan on naming your main server any different, change your "main": (whatever your main server filename is called).
works for me
Awesome
How to handle this custom error message returned from node api in angular 8 for me I'm unable to receive in the POST example though I'm returning the message as json.., Please help me for this..
is there any way to reduce errors when it comes to API calls?
You are great
Sir I have little bit doubt about that , this error handling works with database or not...
how did the 404 error and 500 or any 500 types error was shown by the code ??
This works as well.
app.use((req,res)=>{
const error = new Error('Not Found');
error.status = 404 || 500;
res.send({
Error: 'Page not found',
Status: error.status
})
});
Hey Max, love your videos and I'm a student of yours at udemy(react), I need a quick little advice but on node.js, can you help me?
I know it's late but can you ask your question? I will try to help
how to stop nodemon server? Coz i've been trying to press the rectangular stop button in console but it won't stop ! It keeps on running
CNTRL + C on windows CMD + C on osx
Why does it says nodemon cannot find express module ? O.O
It has no dislikes for a reason :)
some jack ass disliked this video! let's GET HIM!!! haha
Did you decide to switch from WebStorm to VS, why? )
I basically switched Andrey, yes. Some parts are still missing/ better in Webstorm but VS Code is faster and I like working with it. If auto-imports and code formatting gets bit better, there'll be nothing I miss
Is there a framework for this sort of setup? So that you don't have to create like all the error stuff every time and so on?
There a REST-focused frameworks, yes - you may have a look at Loopback for example (loopback.io/)
Is it recommended to use such framework, or is it better to set up your own, what is your opinion? :)
Hi Max,
when is next videos coming?
Today Sumit ;)
Why have not used app.get('/...')
Instead of router.get('/...')?
Is there is a difference or like best practice or something?
Yes, its always good practice to separate different routes into their own js file. You wouldn't want to clutter up the app.js file with a bunch of routes that ultimately are going to "different" endpoints. Exporting and then requiring the routes from the routes folder allows your app.js to look cleaner. In this example there arent a lot of different endpoints (orders and products), but in production, a real api can have a lot more.
why are you using const variables ?
Because this variables will not redefined in future.
nodemon replaced by mode --watch {filename}...version 18 and above
nodemon is not working inside a subdirectory.
do you have any documents?
Sorry, but which documents do you mean?
nodemon doesn't work in window 10. so use "forever" npm install forever then run forever -w server.js
uninstall window 10
Why? I'm have Win10 and nodemon work good.
I love you
If your doesn't show the error, just restart the server
I just use nodemon . everthing runs fine at 1:53
aorors
I love your vids and have been watching them for ages but can you please not type so fast. I have to rewind all the time :-(
Thank you for your support and for your feedback! I'll try to keep that in mind for future videos :)
In terminal use npm start not nodeman server.js its not working might depracted.
I got error at req.body.images.length
The error is “cannot read the property ‘length’ of undefined”