How to read multi part form in node.js

I have a node.js application which currently supports only x-www-form-urlencoded requests. If someone needs to send a file as an attachment I have to extend the support for form-data. Reading the data from request is currently done using DecodeURIComponent and look similar to following. Is it possible to adapt this to read form data?

exports.parseUrlEncodedBody = function(event) {

  //This is to extract url encoded data

  var temp = {};

  if (event.body) {
    // retrieve keys & values
    var pm = event.body.split("&");

    // store keys and values in temp object
    params.forEach(function (item, index, array) {
      var keyValue = item.split("=");
      var key, value;
      if (keyValue.length >= 1) {
        key = decodeURIComponent(keyValue[0]);
        if (keyValue.length >=2) {
          value = decodeURIComponent(keyValue[1]);
        } else {
          value = "";

        temp[key] = value;

Is it possible to adapt this to read form data?

No. The data format is completely different. You would need to rewrite it from scratch.

Consider using a module such as multer which is designed for this.

If you want to write your own library from scratch, then you should consult RFC 7578, which describes the data format.