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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@dropinblog/react-express

v1.0.2

Published

Express SSR middleware for @dropinblog/react-core

Readme

@dropinblog/react-express

Express SSR middleware for integrating DropInBlog with your Express application.

Features

  • Server-side rendering – Render DropInBlog content on the server for SEO and performance
  • Express middleware – Easy integration with Express apps
  • Customizable HTML – Full control over rendered HTML templates
  • Automatic routing – Handles blog routes automatically
  • Built on react-core – Uses @dropinblog/react-core under the hood

Installation

npm install @dropinblog/react-express
# or
yarn add @dropinblog/react-express

Configuration

Set your credentials in the environment (recommended):

DROPINBLOG_BLOG_ID=your_dropinblog_blog_id
DROPINBLOG_API_TOKEN=your_dropinblog_api_token

Basic Usage

import express from 'express';
import { createDropInBlogExpressMiddleware } from '@dropinblog/react-express';

const app = express();

// Add DropInBlog middleware for all /blog routes
app.use('/blog', createDropInBlogExpressMiddleware({
  basePath: '/blog',
}));

Advanced Usage

Custom HTML Template

Provide your own HTML rendering function:

import { createDropInBlogExpressMiddleware, renderHeadTags } from '@dropinblog/react-express';

app.use('/blog', createDropInBlogExpressMiddleware({
  basePath: '/blog',
  renderHtml: ({ content, headDescriptors, pathname }) => {
    const headTags = renderHeadTags(headDescriptors);

    return `<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    ${headTags}
    <link rel="stylesheet" href="/styles.css">
  </head>
  <body>
    <header>
      <nav>
        <a href="/">Home</a>
        <a href="/blog">Blog</a>
      </nav>
    </header>
    <main>
      <div id="dropinblog-content">${content}</div>
    </main>
    <footer>
      <p>&copy; 2024 My Company</p>
    </footer>
    <script src="/app.js"></script>
  </body>
</html>`;
  }
}));

Error Handling

Handle errors with a custom error handler:

app.use('/blog', createDropInBlogExpressMiddleware({
  basePath: '/blog',
  onError: (error, req, res) => {
    console.error('DropInBlog error:', error);
    res.status(500).render('error', {
      message: 'Failed to load blog content',
      error
    });
  }
}));

Custom 404 Handler

Provide a custom handler for non-matching routes:

app.use('/blog', createDropInBlogExpressMiddleware({
  basePath: '/blog',
  notFoundHandler: (req, res, next) => {
    res.status(404).render('404', {
      path: req.path
    });
  }
}));

API Reference

createDropInBlogExpressMiddleware(options)

Creates an Express middleware function for rendering DropInBlog content.

Options

  • basePath (string, optional): Base path for blog routes. Default: /blog
  • blogId (string, optional): Your DropInBlog blog ID. Defaults to DROPINBLOG_BLOG_ID env var
  • apiToken (string, optional): Your DropInBlog API token. Defaults to DROPINBLOG_API_TOKEN env var
  • cacheTtlMs (number, optional): Cache TTL in milliseconds. Default: 300000 (5 minutes)
  • renderHtml (function, optional): Custom HTML rendering function
  • onError (function, optional): Custom error handler
  • notFoundHandler (RequestHandler, optional): Custom 404 handler

Utility Functions

renderHeadTags(descriptors: HeadDescriptor[]): string

Converts head descriptors to HTML string.

renderHtmlTemplate(options: HtmlTemplateOptions): string

Renders a complete HTML document with the provided options.

escapeHtml(str: string): string

Escapes HTML special characters.

Supported Routes

The middleware automatically handles these route patterns (with /blog as the base path):

  • /blog - Main blog listing
  • /blog/page/{page} - Paginated blog listing
  • /blog/category/{slug} - Category listing
  • /blog/category/{slug}/page/{page} - Paginated category listing
  • /blog/author/{slug} - Author listing
  • /blog/author/{slug}/page/{page} - Paginated author listing
  • /blog/{post-slug} - Individual blog post
  • /blog/sitemap.xml - XML sitemap generated by DropInBlog
  • /blog/feed - Main RSS feed
  • /blog/feed/category/{slug} - Category RSS feed
  • /blog/feed/author/{slug} Author RSS feed

Requirements

  • Node.js >= 18
  • React >= 18.2
  • Express >= 4.18

License

MIT © DropInBlog