npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

guardify

v1.0.2

Published

Guardify is a Node.js middleware designed to enhance the security of your web applications by setting various HTTP security headers. It is easy to integrate and customizable based on your specific security requirements.

Readme

Guardify Middleware (Express.js) Test Coverage

Guardify Middleware (Express.js)

Guardify is a Node.js middleware designed to enhance the security of your web applications by setting various HTTP security headers. It is easy to integrate and customizable based on your specific security requirements.

Installation

npm i guardify

Usage

Integrate the Guardify middleware into your Express application to effortlessly enhance its security. The middleware comes with default settings, but you can easily customize its behavior based on your specific security requirements.

Ensure to place the middleware early in your middleware stack to ensure that security headers are set for every incoming request. Refer to the example below for a quick setup with both default and custom options.

const express = require('express');
const Guardify = require('guardify');

const app = express();

// Use Guardify middleware with default options
app.use(Guardify());

// Or customize options
app.use(Guardify({
    enableHSTS: true,
    hstsMaxAge: 31536000,
    enableXXSprotection: true,
    enableXFrameOptions: true,
    poweredBy: true,
    enableCORS: true,
    corsOrigin: '*',
    corsMethods: 'GET, POST, PUT, DELETE',
    corsHeaders: 'Content-Type, Authorization',
    referrerPolicy: 'no-referrer-when-downgrade',
    permissionsPolicy: 'geolocation=(self), microphone=()',
    customHeaders: {
        'X-Custom-Header': 'CustomValue'
    }
}));

// Your routes and application logic go here

app.listen(3001, () => {
    console.log('Server is running on port 3001');
});

Note: By default, Guardify comes with a well-configured set of security headers but is flexible enough to adjust the options as needed.

Tip: Guardify's default configuration automatically disables exposure of the technology behind the web application, enhancing security.

Warning: When using security middleware like Guardify, it is generally recommended to place it at the top of your middleware stack. This ensures that the security headers are set for every incoming request before other middleware or route handlers are executed.

Options

| Option | Default | Description | |-----------------------|---------|-------------| | enableHSTS | true | Enables HTTP Strict Transport Security (HSTS) to enforce HTTPS-only communication. | | hstsMaxAge | 31536000 | Sets the max age for HSTS in seconds (default: 1 year). | | enableXXSprotection | true | Enables X-XSS-Protection header to prevent cross-site scripting (XSS) attacks. | | enableXFrameOptions | true | Enables X-Frame-Options header to protect against clickjacking attacks. | | poweredBy | true | Removes the X-Powered-By header for security through obscurity. | | enableCORS | false | Enables Cross-Origin Resource Sharing (CORS) headers. | | corsOrigin | * | Specifies allowed origins for CORS (default: *). | | corsMethods | 'GET, POST, PUT, DELETE' | Specifies allowed HTTP methods for CORS. | | corsHeaders | 'Content-Type, Authorization' | Specifies allowed HTTP headers for CORS. | | referrerPolicy | 'no-referrer-when-downgrade' | Controls how much referrer information is included with requests. | | permissionsPolicy | 'geolocation=(self), microphone=()' | Defines browser feature permissions. | | customHeaders | {} | Allows adding additional custom headers as key-value pairs. |

Best Practices

  • Place Guardify at the top of your middleware stack to ensure security headers are applied before other middleware.
  • Keep enableHSTS, enableXXSprotection, and enableXFrameOptions enabled unless specific application requirements dictate otherwise.
  • Adjust hstsMaxAge based on your application's needs.
  • Regularly review and update security headers based on emerging best practices and changes in your application's requirements.

Security Headers

  • Strict-Transport-Security (HSTS): Protects against man-in-the-middle attacks by enforcing HTTPS usage.
  • X-XSS-Protection: Prevents cross-site scripting (XSS) attacks.
  • X-Frame-Options: Protects against clickjacking attacks.
  • X-Powered-By: Optional - Removes the 'X-Powered-By' header for security through obscurity.
  • Referrer-Policy: Controls how much referrer information is included with requests.
  • Permissions-Policy: Restricts the use of certain browser features to improve security.
  • CORS Headers (Optional): Allows cross-origin requests when enabled.

With Guardify, you can ensure your application is well-protected while maintaining flexibility for customization. 🚀