Handling Errors & Improving the Project Setup | Creating a REST API with Node.js

Sdílet
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!

Komentáře • 128

  • @racheljohnson2006
    @racheljohnson2006 Před 3 lety +9

    4 videos in and I just realized that there are no ads. Sir, I hope you get all the recognition you deserve!

  • @derekdemaria6728
    @derekdemaria6728 Před 6 lety +14

    Thank you for making this series, I appreciate the help!

    • @academind
      @academind  Před 6 lety +4

      Thank YOU for your awesome feedback Derek!

  • @RicardoFAlves-mp3cb
    @RicardoFAlves-mp3cb Před 6 lety +50

    Even when you are wrong, things works as expected. Great guy hahaha

    • @LasradoRohan
      @LasradoRohan Před 3 lety +1

      That is actually a build up to a bigger punch in the face

  • @maleeshpamuditha8010
    @maleeshpamuditha8010 Před 2 lety

    Thanks max always improves my coding with your tutorials. ❤️

  • @martinlupa8692
    @martinlupa8692 Před 2 lety

    Your courses and videos are just amazing!

  • @timharris72
    @timharris72 Před 6 lety +4

    This was very helpful. You are awesome. Keep making more videos like this!!

    • @academind
      @academind  Před 6 lety +1

      I will, thanks for your awesome feedback!

  • @realOjive
    @realOjive Před 4 měsíci

    Maaaaaaaan. This is great! Insanely helpfull, easy to understand, actually fun to follow!

  • @code_react
    @code_react Před 2 lety

    You are the best instructor on Udemy. I really enjoy your teaching method.

  • @octav7438
    @octav7438 Před 3 lety

    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.

  • @kerendn
    @kerendn Před 5 lety +1

    Fantastic tutorial series so far. Thank you.

    • @academind
      @academind  Před 5 lety

      Very happy to read that you like it Keren, thanks a lot!

  • @syahrizalsetiawan1870
    @syahrizalsetiawan1870 Před 5 lety +1

    Finally i know what is RESTful API and the function . Thanks. Subscribed

    • @academind
      @academind  Před 5 lety

      Thank you Syahrizal, great to have you on board of the channel!

  • @wederpacheco1470
    @wederpacheco1470 Před 6 lety +3

    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!

    • @academind
      @academind  Před 6 lety +2

      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!

  • @bassam.2023
    @bassam.2023 Před 10 měsíci

    I did this whole tutorial about 3 years ago, still refer to it on occasion, as I am now. Love Max and Manu! ❤

  • @yashwants18
    @yashwants18 Před 5 měsíci

    one of the best serious on apis.... nice serious thanks

  • @alexandernikolaychuk8405
    @alexandernikolaychuk8405 Před 6 lety +4

    I like all your cources, good job :)

    • @academind
      @academind  Před 6 lety +5

      That's so awesome to read, thanks a lot!

  • @israelruas948
    @israelruas948 Před 5 měsíci

    Very happy with all videos

  • @schlaus_kwab
    @schlaus_kwab Před 5 lety +5

    I've finished a couple of Max's courses on Udemy, too. As always, great material, great teaching. Thanx, Max!

    • @academind
      @academind  Před 5 lety +1

      That's just fantastic to read Sharis, thanks a lot for your awesome feedback!

  • @meyyappanmuthuraman4763
    @meyyappanmuthuraman4763 Před 5 lety +1

    Awesome video. Just found your channel today and immediately subscribed.

    • @academind
      @academind  Před 5 lety

      So happy to have you on board Meyyappan, thank you for your support!

  • @curiousprogrammer90
    @curiousprogrammer90 Před 6 lety

    Keep it up man! Best channel for nodejs/express!!!

  • @FawadSurosh
    @FawadSurosh Před 4 lety

    Wonderful explanation! nice and simple but more beneficial!

  • @nguyentoanhnt
    @nguyentoanhnt Před 3 lety

    Thanks . Your videos are great!

  • @fredhair
    @fredhair Před 4 lety +3

    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!

  • @josuegisber8150
    @josuegisber8150 Před 6 lety

    Very well explained. I think is very clear and understandable.

    • @academind
      @academind  Před 6 lety

      That's really great to read Josue, thank you very much for your support!

  • @maluaalu
    @maluaalu Před 4 lety +2

    Helped me understand my work's code better. Thank you!

  • @qotaybamohammad1679
    @qotaybamohammad1679 Před 4 lety +1

    Although I do not know English I follow you because your channel is beautiful && Thanks

  • @lakers24kobebr
    @lakers24kobebr Před 6 lety

    Great content as always!

  • @LesJoee
    @LesJoee Před 6 lety

    So much fun and so much help.

    • @academind
      @academind  Před 6 lety

      Happy to read that, thank you Jesse!

  • @trdngy8230
    @trdngy8230 Před 5 lety

    Thanks Max!

  • @vinothkumarv9722
    @vinothkumarv9722 Před 3 lety

    Again and again Bro you are great did well.. very good explanation.... love you brother. :)

  • @Ashok2048
    @Ashok2048 Před 4 lety

    Excellent tutorials

  • @karthikeyanm4927
    @karthikeyanm4927 Před 6 lety +1

    not even a single downvote. that explain everyone love this course. Fantastic tutorial. i love learning Node now.

    • @academind
      @academind  Před 6 lety +1

      It's so great to get such a wonderful feedback from you and all the others here on the channel, thanks so much Karthikeyan!

  • @FinanzMinimalist
    @FinanzMinimalist Před 6 lety +1

    Awesome! Keep on going :)

    • @academind
      @academind  Před 6 lety +3

      Videos will keep coming - thanks for your great feedback! :)

  • @abou7miedsoft
    @abou7miedsoft Před 4 lety +1

    This is great!, but I think we should check the caught error cuz some errors should not be returned to the client

  • @Sortepr
    @Sortepr Před 4 lety

    Great tutorial :)

  • @Ethorbit
    @Ethorbit Před 4 lety

    Great tutorials as always.

  • @AbhishekKumar-mq1tt
    @AbhishekKumar-mq1tt Před 6 lety

    Thank you for this awesome video

    • @academind
      @academind  Před 6 lety

      Thank YOU for your comment Abhishek :)

  • @wilhelmlundstrom2018
    @wilhelmlundstrom2018 Před 6 lety +8

    couldnt you make nodemon global by using the -g tag when installing?

  • @maxlev621
    @maxlev621 Před 6 lety

    Really good tuts series

    • @academind
      @academind  Před 6 lety

      So great to read that, thank you Max!

    • @maxlev621
      @maxlev621 Před 6 lety

      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.

  • @hamzajaved6110
    @hamzajaved6110 Před rokem

    SPEECHLESS 👌👌

  • @Jgs8115
    @Jgs8115 Před 5 lety

    Aulas ótimas, salvou !!

  • @hekaya28
    @hekaya28 Před 5 lety

    very good keep going

  • @kazeemodutola9617
    @kazeemodutola9617 Před 5 lety

    Great video! please can you make a video on api units test endpoins using mocha or jasmine?

  • @realsunjian
    @realsunjian Před rokem

    I like it, Sir.

  • @yashone7
    @yashone7 Před 4 lety

    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?

  • @explorer9004
    @explorer9004 Před rokem

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

  • @hub7digital413
    @hub7digital413 Před 5 lety +1

    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,

  • @zaylo9273
    @zaylo9273 Před 4 lety

    so is it better to download as global instead or type individually? I love the detailed videos. Thank you for teaching us! XD

  • @brucebane7401
    @brucebane7401 Před 3 lety

    amazing!!!!!

  • @AmitKumarKhare
    @AmitKumarKhare Před 6 lety

    Great tutorials. :)

  • @sergiopostigo1412
    @sergiopostigo1412 Před 2 lety +1

    Why is morgan response time different than the one in postman?

  • @daniellaerachannel
    @daniellaerachannel Před 6 lety

    nice video!!

    • @academind
      @academind  Před 6 lety

      Thanks! Happy to hear you're enjoying it!

  • @sheikhabdullah6574
    @sheikhabdullah6574 Před 5 lety

    Welcome to this "SERIOUS" ! :)

  • @MrAamir33
    @MrAamir33 Před 4 lety

    Hey great explaination I just have one doubt wouldnt the error handler middleware executes for every request for ok as well as bad ones ?

    • @sabujjana2860
      @sabujjana2860 Před 4 lety

      the ok requests are consumed by /products and /orders and returned. so they do not trickle down to the end

  • @SLMYanimatic
    @SLMYanimatic Před 4 měsíci

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

  • @omgerplayz
    @omgerplayz Před 4 lety

    works for me

  • @Alpha777beta
    @Alpha777beta Před 5 lety

    Awesome

  • @karthikbalasubramanya
    @karthikbalasubramanya Před 4 lety

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

  • @jasonpatel6562
    @jasonpatel6562 Před 3 lety

    is there any way to reduce errors when it comes to API calls?

  • @sreekanthsreenivasan8534

    You are great

  • @shwetaverma4770
    @shwetaverma4770 Před 4 lety

    Sir I have little bit doubt about that , this error handling works with database or not...

  • @nitishsingh4177
    @nitishsingh4177 Před 2 lety

    how did the 404 error and 500 or any 500 types error was shown by the code ??

  • @MS-xu1ks
    @MS-xu1ks Před 4 lety

    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
    })
    });

  • @joaoalegria7578
    @joaoalegria7578 Před 4 lety +2

    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?

    • @aryanshmahato
      @aryanshmahato Před 4 lety +2

      I know it's late but can you ask your question? I will try to help

  • @razorguy13396
    @razorguy13396 Před 5 lety

    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

    • @thehaptiK
      @thehaptiK Před 5 lety

      CNTRL + C on windows CMD + C on osx

  • @duftcola
    @duftcola Před 5 lety

    Why does it says nodemon cannot find express module ? O.O

  • @isoplayers
    @isoplayers Před 5 lety +1

    It has no dislikes for a reason :)

    • @thehaptiK
      @thehaptiK Před 5 lety

      some jack ass disliked this video! let's GET HIM!!! haha

  • @Andrey-il8rh
    @Andrey-il8rh Před 6 lety

    Did you decide to switch from WebStorm to VS, why? )

    • @academind
      @academind  Před 6 lety +4

      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

  • @ALNUDN
    @ALNUDN Před 6 lety

    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?

    • @academind
      @academind  Před 6 lety

      There a REST-focused frameworks, yes - you may have a look at Loopback for example (loopback.io/)

    • @ALNUDN
      @ALNUDN Před 6 lety

      Is it recommended to use such framework, or is it better to set up your own, what is your opinion? :)

  • @sumeetsood232
    @sumeetsood232 Před 6 lety

    Hi Max,
    when is next videos coming?

  • @yashwardhanpauranik1670

    Why have not used app.get('/...')
    Instead of router.get('/...')?
    Is there is a difference or like best practice or something?

    • @khassen.7
      @khassen.7 Před 5 lety +1

      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.

  • @muhammadawais7563
    @muhammadawais7563 Před 6 lety

    why are you using const variables ?

    • @MrSharkeron
      @MrSharkeron Před 5 lety

      Because this variables will not redefined in future.

  • @aarjyabharadwaz7329
    @aarjyabharadwaz7329 Před 10 měsíci

    nodemon replaced by mode --watch {filename}...version 18 and above

  • @anshul90100
    @anshul90100 Před 6 lety

    nodemon is not working inside a subdirectory.

  • @learnfromthisthat4428
    @learnfromthisthat4428 Před 6 lety

    do you have any documents?

    • @academind
      @academind  Před 6 lety

      Sorry, but which documents do you mean?

  • @sudhir600
    @sudhir600 Před 5 lety

    nodemon doesn't work in window 10. so use "forever" npm install forever then run forever -w server.js

  • @aris13pat1
    @aris13pat1 Před 6 měsíci

    I love you

  • @Onyecode
    @Onyecode Před 11 měsíci

    If your doesn't show the error, just restart the server

  • @hotmandead1
    @hotmandead1 Před 5 lety

    I just use nodemon . everthing runs fine at 1:53

  • @hrishikeshethape3960
    @hrishikeshethape3960 Před 4 lety

    aorors

  • @2wheelsonline
    @2wheelsonline Před 6 lety

    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 :-(

    • @academind
      @academind  Před 6 lety +1

      Thank you for your support and for your feedback! I'll try to keep that in mind for future videos :)

  • @jeevu94
    @jeevu94 Před 4 lety

    In terminal use npm start not nodeman server.js its not working might depracted.

  • @ramponnada2795
    @ramponnada2795 Před 2 lety

    I got error at req.body.images.length
    The error is “cannot read the property ‘length’ of undefined”