Search code examples
expressmiddlewareurlencodenode.js-connectform-processing

How to re-add/include the express/connect json() and urlencoded() parsers that were removed from connect?


So the connect guys removed my urlencoder and json parser. Absolutely nothing wrong with those middlewares and I'd like to continue using them to send emails and retrieve form input data.

Note: I am not dealing with any type or form of file uploading. Also, I tried going over to the link the error message provides when I try and use the express/connect.urlencoded() and express/connect.json() and I ended up wasting two hours clicking from github to github. I don't want an over bloated file uploader. Just my simple form parser, without the file upload. Just doesn't make sense to remove the two working middleware because of one faulty middleware.


Solution

  • In Express 4, all bundled middleware (except static) has been removed - however, you can still install it via npm:

    npm install --save body-parser
    

    and require it in your app:

    var bodyParser = require('body-parser');
    // ...
    app.use(bodyParser());
    

    Consult this article for information about migrating from Express 3 to 4:

    http://scotch.io/bar-talk/expressjs-4-0-new-features-and-upgrading-from-3-0

    It has a nice table if you scroll down a bit where it lists what the bundled middleware was called in Express 3, and the corresponding name of the package if you want to use it in Express 4.

    There's also the official Express 4 migration guide here:

    https://github.com/visionmedia/express/wiki/Migrating-from-3.x-to-4.x