Skip to content

Zingle/express-ndjson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The @zingle/express-ndjson library provides Express.js middleware to handle incoming ND-JSON streams of JSON documents.

Usage

Basic Usage

For simple usage with default behavior, you can pass a document handler function to the middleware. This middleware will accept requests as JSON or ND-JSON and pass parsed documents to the document handler.

const express = require("express");
const ndjson = require("@zingle/express-ndjson");
const app = express();

app.post("_bulk", ndjson(doc => {
    // handle parsed JSON document
}));

Custom Usage

You can pass several options to the middleware to customize the behavior. When passing options, pass the document handler as an option named "documentHandler".

const express = require("express");
const ndjson = require("@zingle/express-ndjson");
const app = express();

app.post("_bulk", ndjson({
    maxSize: 102400,                // max size of document in bytes
    maxDocuments: 500,              // max number of documents in stream
    errorHandler: console.error,    // pass errors to handler
    documentHandler: doc => {       // pass parsed documents to handler
        // handle parsed JSON document
    }
}));

About

Express.js middleware to ingest NDJSON stream

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published