
Security News
n8n Tops 2025 JavaScript Rising Stars as Workflow Platforms Gain Momentum
n8n led JavaScript Rising Stars 2025 by a wide margin, with workflow platforms seeing the largest growth across categories.
http-ndjson
Advanced tools
Log http requests as ndjson.
$ npm install http-ndjson
const httpNdjson = require('http-ndjson')
const http = require('http')
http.createServer((req, res) => {
httpNdjson(req, res).pipe(process.stdout)
res.end()
}).listen()
{ name: 'http', method: 'GET', message: 'request', url: '/' }
{ name: 'http', method: 'GET', message: 'response', url: '/', statusCode: 200, elapsed: '5ms' }
Sometimes process.stdout is not quite what you're looking for. Because
http-ndjson is a stream it can easily plug into any streaming logger:
const boleStream = require('bole-stream')
const httpNdjson = require('http-ndjson')
const bole = require('bole')
const http = require('http')
bole.output({ level: 'info', stream: process.stdout })
http.createServer((req, res) => {
httpNdjson(req, res).pipe(boleStream({ level: 'info' }))
res.end()
}).listen()
const bunyanStream = require('bunyan-stream')
const httpNdjson = require('http-ndjson')
const bunyan = require('bunyan')
const logger = bunyan.createLogger({ name: 'myApp' })
http.createServer((req, res) => {
httpNdjson(req, res).pipe(bunyanStream({ level: 'info' }, logger))
res.end()
}).listen()
http-ndjson can set a responseSize property on the response. It's
recommended to use the size-stream
package.
const httpNdjson = require('http-ndjson')
const sizeStream = require('size-stream')
const http = require('http')
http.createServer((req, res) => {
const httpLogger = httpNdjson(req, res)
httpLogger.pipe(process.stdout)
const size = sizeStream()
size.once('size', size => httpLogger.setSize(size))
req.pipe(size).pipe(res)
}).listen()
http-ndjson logs a sensible set of standard properties, but sometimes there's
a need to dive in and log more. An optional third argument can be added with
custom fields that will be logged on either request or response.
const httpNdjson = require('http-ndjson')
const http = require('http')
http.createServer((req, res) => {
const opts = { req: { requestId: req.headers['requestId'] } }
httpNdjson(req, res, opts)
res.end()
}).listen()
Determining the origin of a request can be hard when using reverse-proxies.
It's not too uncommon for users to mask their IP by providing an
x-forwarded-for header. http-ndjson makes no assumptions about forwarding
headers and logs all properties instead. The following headers are logged:
Create an http logger. Returns a write stream. Opts can contain the following values:
requestresponseSet the content length in bytes.
FAQs
Log http requests as ndjson
We found that http-ndjson demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
n8n led JavaScript Rising Stars 2025 by a wide margin, with workflow platforms seeing the largest growth across categories.

Security News
The U.S. government is rolling back software supply chain mandates, shifting from mandatory SBOMs and attestations to a risk-based approach.

Security News
crates.io adds a Security tab backed by RustSec advisories and narrows trusted publishing paths to reduce common CI publishing risks.