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

cloudflare-error-page

v0.1.0

Published

Cloudflare Error Page Generator

Downloads

182

Readme

Cloudflare Error Page Generator (Node.js/TypeScript)

Carbon copy of the original Python version.

Installation

npm install cloudflare-error-page

Or install from GitHub:

npm install git+https://github.com/donlon/cloudflare-error-page.git#main:nodejs

Quick Start

import { render } from 'cloudflare-error-page';
import * as fs from 'fs';

const errorPage = render({
  browser_status: { status: 'ok' },
  cloudflare_status: { status: 'error', status_text: 'Error' },
  host_status: { status: 'ok', location: 'example.com' },
  error_source: 'cloudflare',
  what_happened: '<p>There is an internal server error on Cloudflare\'s network.</p>',
  what_can_i_do: '<p>Please try again in a few minutes.</p>',
});

fs.writeFileSync('error.html', errorPage);

API Reference

render(params: ErrorPageParams, allowHtml?: boolean): string

Generates an HTML error page based on the provided parameters.

Parameters

  • params: An object containing error page configuration
  • allowHtml (optional): Whether to allow HTML in what_happened and what_can_i_do fields. Default: true

ErrorPageParams Interface

interface ErrorPageParams {
  // Basic information
  error_code?: number;              // Default: 500
  title?: string;                   // Default: 'Internal server error'
  html_title?: string;              // Default: '{error_code}: {title}'
  time?: string;                    // Auto-generated if not provided
  ray_id?: string;                  // Auto-generated if not provided
  client_ip?: string;               // Default: '1.1.1.1'
  
  // Status for each component
  browser_status?: StatusItem;
  cloudflare_status?: StatusItem;
  host_status?: StatusItem;
  
  // Error source indicator
  error_source?: 'browser' | 'cloudflare' | 'host';
  
  // Content sections
  what_happened?: string;           // HTML content
  what_can_i_do?: string;           // HTML content
  
  // Optional customization
  more_information?: MoreInformation;
  perf_sec_by?: PerfSecBy;
  creator_info?: CreatorInfo;
}

interface StatusItem {
  status?: 'ok' | 'error';
  status_text?: string;             // Default: 'Working' or 'Error'
  status_text_color?: string;       // CSS color
  location?: string;
  name?: string;
}

Examples

Basic Error Page

import { render } from 'cloudflare-error-page';

const html = render({
  cloudflare_status: { status: 'error' },
  error_source: 'cloudflare',
  what_happened: '<p>Something went wrong.</p>',
  what_can_i_do: '<p>Try again later.</p>',
});

Express.js Integration

import express from 'express';
import { render } from 'cloudflare-error-page';

const app = express();

app.use((err, req, res, next) => {
  const errorPage = render({
    error_code: err.status || 500,
    title: err.message || 'Internal server error',
    cloudflare_status: { status: 'ok' },
    host_status: { 
      status: 'error',
      location: req.hostname 
    },
    error_source: 'host',
    what_happened: `<p>${err.message}</p>`,
    what_can_i_do: '<p>Please try again or contact support.</p>',
  });
  
  res.status(err.status || 500).send(errorPage);
});

TypeScript Support

This package includes full TypeScript type definitions. Import types as needed:

import { render, ErrorPageParams, StatusItem } from 'cloudflare-error-page';

License

MIT

Related