You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

on-headers

Package Overview
Dependencies
Maintainers
3
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

on-headers

Execute a listener when a response is about to write headers

1.1.0
latest
Source
npmnpm
Version published
Weekly downloads
27M
3.62%
Maintainers
3
Weekly downloads
 
Created

What is on-headers?

The on-headers npm package is used to execute custom logic when headers are about to be written to the response object in a Node.js HTTP server. This can be useful for logging, setting default headers, or performing other actions based on the headers before they are sent to the client.

What are on-headers's main functionalities?

Execute custom logic before headers are sent

This code sample demonstrates how to use the on-headers package to execute a function right before the headers are sent in an HTTP response. The function `onHeadersListener` is called just before the headers are written to the response.

const onHeaders = require('on-headers');

function onHeadersListener(res) {
  console.log('Headers will be sent soon.');
  // Perform any custom logic here
}

http.createServer(function (req, res) {
  onHeaders(res, onHeadersListener);
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World!');
});

Other packages similar to on-headers

Keywords

event

FAQs

Package last updated on 17 Jul 2025

Did you know?

Socket

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.

Install

Related posts