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 🙏

© 2024 – Pkg Stats / Ryan Hefner

serve-dynamic-favicon

v0.1.0-alpha2

Published

middleware that serve dynamically generated favicons

Downloads

2

Readme

serve-dynamic-favicon

PLEASE NOTE THIS IS IN ALPHA

Node.js middleware for serving a favicon that is generated on the fly. Using the first letter of the the <title> tag overlayed a background color fetched from the <meta name="theme-color" content="#007BB6"> you'll reduce the cognitive load when switching between browser tabs. You may specify any url you want for where the metadata will be fetched from, or you can pass the letter and theme-color and save the initial request. This is very useful for when you're running expressjs or BrowserSync servers.

Install

npm install serve-dynamic-favicon --production --no-optional

API

favicon(url:string || options:object)

Create new middleware to serve a favicon generated from metadata fetched from the given url to a fetchable html document. Pass an object with options to switch the middleware from auto mode to manual mode. Manual mode require you to at least specify themeColor. symbol is optional, omitting it will render a solid color without any foreground text as logo.

Options

themeColor

The backdrop color to the generated icon. Any css color value, with or without alpha, is supported.

symbol

The text letter, usually the first character found in the <title> tag when url is defined.

symbolColor

Optionally set the color of symbol. Defaults to #ffffff.

Examples

Typically this middleware will come very early in your stack (maybe even first) to avoid processing any other middleware if we already know the request is for /favicon.ico.

express

var express = require('express');
var favicon = require('serve-dynamic-favicon');

var app = express();
app.use(favicon('https://github.com'));

// Add your routes here, etc.

app.listen(3000);

connect

var connect = require('connect');
var favicon = require('serve-dynamic-favicon');

var app = connect();
app.use(favicon('https://github.com'));

// Add your middleware here, etc.

app.listen(3000);

vanilla http server

This middleware can be used anywhere, even outside express/connect. It takes req, res, and callback.

var http = require('http');
var favicon = require('serve-dynamic-favicon');
var finalhandler = require('finalhandler');

var _favicon = favicon();

var server = http.createServer(function onRequest(req, res) {
  var done = finalhandler(req, res);

  _favicon(req, res, function onNext(err) {
    if (err) return done(err);

    // continue to process the request here, etc.

    res.statusCode = 404;
    res.end('oops');
  });
});

server.listen(3000);

License

MIT