Registry / web-framework / connect-fonts

connect-fonts

JSON →
library2.1.5jsnpmunverified

Connect/Express middleware for serving web fonts with browser-specific @font-face CSS. Version 2.1.5 is the latest stable release. It allows serving fonts from your own domain instead of relying on external CDNs like Google Fonts, reducing latency. Font packs are installed separately (e.g., connect-fonts-opensans), and the middleware generates CSS tailored to the user's user-agent. Supports locale-optimized subsets, CORS headers, caching, and programmatic CSS generation for build steps. Compared to alternatives, it provides full control over font delivery and is ideal for performance-conscious Express apps.

npm install connect-fonts
INSTALL
IMPORT
SIG · CONNECT-FONTS
C
connect-fonts
web-frameworkjavascriptv2.1.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const fontMiddleware = require('connect-fonts');
import fontMiddleware from 'connect-fonts';
Package is CJS-only; ESM import not supported.
setup
fontMiddleware.setup({ fonts: [require('connect-fonts-opensans')] })
fontMiddleware({ fonts: [...] })
setup() is a method on the default export, not the default itself.
generate_css
const middleware = fontMiddleware.setup({...}); middleware.generate_css(ua, lang, fonts, callback);
fontMiddleware.generate_css(ua, lang, fonts, callback);
generate_css is an instance method returned by setup().

Express server serving Open Sans font via connect-fonts middleware.

const express = require('express'); const fontMiddleware = require('connect-fonts'); const opensans = require('connect-fonts-opensans'); const app = express(); const port = process.env.PORT || 3000; app.use(fontMiddleware.setup({ fonts: [opensans], allow_origin: 'https://example.com', ua: 'all', maxage: 180 * 24 * 60 * 60 * 1000 // 180 days })); app.get('/', (req, res) => { res.send('<link href="/opensans-regular/fonts.css" rel="stylesheet" /><style>body { font-family: "Open Sans", sans-serif; }</style><h1>Hello!</h1>'); }); app.listen(port, () => console.log(`Server on port ${port}`));
Debug
Known issues
deprecatedconnect-fonts is no longer actively maintained; last release 2018.
fix
Consider alternatives like Express.js built-in static or CDN-hosted fonts.
affects: >=2.0.0
gotchaMiddleware must be mounted before routes that serve HTML referencing fonts.css.
fix
Place app.use(fontMiddleware.setup(...)) before your route handlers.
affects: >=1.0.0
gotchaFont packs are separate npm packages; missing pack results in no fonts served.
fix
Install required pack, e.g., npm install connect-fonts-opensans and require() it.
affects: >=2.0.0
gotchaSetting ua option to 'all' serves all font formats (woff, woff2, etc.) to all browsers, increasing bandwidth.
fix
Omit ua or set to specific user-agent string to send only supported formats.
affects: >=2.0.0
Errors
Common errors & fixes
Error: Cannot find module 'connect-fonts-opensans'
Missing font pack dependency.
fix
npm install connect-fonts-opensans
TypeError: fontMiddleware is not a function
Calling the default export directly instead of calling .setup().
fix
Use fontMiddleware.setup({ ... }) instead of fontMiddleware({ ... }).
Cannot read property 'generate_css' of undefined
generate_css is called on the default export, not the setup return value.
fix
const mw = fontMiddleware.setup(...); mw.generate_css(...);
Upgrade
Version history
2.1.5latest on npm
Audit
Dependencies
connectrequiredUses Connect middleware signature (req, res, next); works with Express.
asyncrequiredUsed internally for async flow control (e.g., parallel font processing).
Agent activity
12 hits · last 30 days
node
10
Amazon
1
OpenAI (training)
1
Resources
connect-fonts — npm install connect-fonts · libregistry