@artemkv/readjsonstream

1.0.0 • Public • Published

@artemkv/readjsonstream - Constructs object from Json stream

const MAX_LENGTH = 512;

const readJsonStream = require('@artemkv/readjsonstream');

function (req, res, next) {
    if (req.method !== 'POST') {
        throw new RestError(statusCodes.MethodNotAllowed, statusMessages.MethodNotAllowed);
    }
    let contentType = req.headers['content-type'];
    if (contentType !== 'application/json') {
        throw new RestError(statusCodes.BadRequest, statusMessages.BadRequest);
    }

    let promise = new Promise(readJsonStream(req, MAX_LENGTH));

    promise
        .then(function (data) {
            console.log(data);

            res.statusCode = statusCodes.OK;
            res.end();
        })
        .catch(function (err) {
            next(err);
        });
}

Readme

Keywords

none

Package Sidebar

Install

npm i @artemkv/readjsonstream

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

2.7 kB

Total Files

4

Last publish

Collaborators

  • artemkv-owner