Hey gang, in this REST API tutorial I’ll show you how we can make some simple middleware to handle our validation errors.

+ Repo –
+ Atom editor –
+ Download GIT –
+ Node.js for Beginners Playlist –
+ MongoDB playlist –

You can find more front-end development tutorials on CSS, HTML, JavaScript, jQuery, WordPress, Node.js & more on the channel homepage…


========== PSD to WordPress Playlist ==========

============ Node.js for Beginners Playlist =============

============== The Net Ninja =====================

For more front-end development tutorials & to black-belt your coding skills, head over to – or

================== Social Links ==================

Twitter – @TheNetNinja –


  1. I'm unable to trigger an error. I'm sending an 'api/post' request without a body to trigger an error, but no error is occurring. The request is going through, even though I have required fields for my schema. Why does this happen?

  2. Hi Ninja! when the document is save in mongo database, the properties "name" and "rank" are not save, just "available" is storaged! Do you know why is happen?

  3. Hey, Im working on a project of my own and I want that the API to interact with both a web app and an Ionic App. The ionic app would be receiving data and store it so that It could be checked by an admin on the web app side. Would you have any recommendations and would this tutorial serve the data in the same way to the Ionic app?

  4. Tnx, great solution!
    I Try implement error handler like this(without "next" in params), but in result app is falling down.
    app.use(function (err, req, res) {
    res.status(422).json({ error: err});
    I understand, "next" pass request to next middleware, but this error handler is last in chain.
    So could you explain please what doing "next" in this case ? Thank you!


Please enter your comment!
Please enter your name here