Registry / http-networking / connect-browser-sync

connect-browser-sync

JSON →
library2.1.0jsnpmunverified

Connect middleware that automatically injects BrowserSync script tags into responses. Version 2.1.0 supports BrowserSync >=2.0.0, with an optional Turbolinks workaround. Released 2015, no recent updates. Compared to Gulp/Grunt plugins, this integrates directly with Connect/Express middleware stack.

npm install connect-browser-sync
INSTALL
IMPORT
SIG · CONNECT-BROWSER-SY
C
connect-browser-sync
http-networkingjavascriptv2.1.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

connect-browser-sync
✓ var connectBrowserSync = require('connect-browser-sync');
✗ import { connectBrowserSync } from 'connect-browser-sync';
CommonJS only; no default or named ESM export. Use require().
browser-sync
✓ var browserSync = require('browser-sync').create();
✗ var bs = require('browser-sync').init({...});
Must call .create() and then .init() on the instance. .init() returns the instance.
middleware invocation
✓ app.use(require('connect-browser-sync')(bs));
✗ app.use(require('connect-browser-sync'));
The middleware factory expects a BrowserSync instance. Do not pass the raw module.

Shows how to set up connect-browser-sync with Express in development mode, injecting BrowserSync scripts.

var express = require('express'); var app = express(); if (app.get('env') === 'development') { var browserSync = require('browser-sync'); var bs = browserSync.create().init({ logSnippet: false }); app.use(require('connect-browser-sync')(bs)); app.get('/hello', function(req, res) { res.send('<html><body>Hello</body></html>'); }); app.listen(3000); }
Debug
Known issues
gotchaMiddleware must be placed before any route/static handlers you want BrowserSync to affect.
fix
Ensure app.use(require('connect-browser-sync')(bs)) appears before app.use(express.static(...)) and route definitions.
affects: >=0.0.0
breakingVersion 2.x only works with browser-sync >=2.0.0. Version 1.x uses browser-sync 1.x.
fix
Upgrade both packages: npm install browser-sync@latest connect-browser-sync@latest
affects: >=2.0.0
deprecatedPackage not updated since 2015, and BrowserSync has evolved. May still work but consider modern alternatives like Vite or webpack HMR.
fix
Evaluate if package is still functional with your BrowserSync version; test thoroughly.
affects: >=2.0.0
gotchaInjection only works on responses with Content-Type: text/html and containing </body> or </head>. Non-HTML responses are ignored.
fix
Ensure your HTML responses have proper doctype and closing body/head tags.
affects: >=0.0.0
gotchaWhen using Turbolinks, set { injectHead: true } to avoid conflicts.
fix
Pass second argument: app.use(require('connect-browser-sync')(bs, { injectHead: true }));
affects: >=2.0.0
Errors
Common errors & fixes
ReferenceError: bs is not defined
Middleware is called with undefined bs variable.
fix
var bs = browserSync.create().init({ logSnippet: false }); app.use(require('connect-browser-sync')(bs));
TypeError: connect-browser-sync is not a function
Missing parentheses: not calling the factory.
fix
app.use(require('connect-browser-sync')(bs));
BrowserSync script tag not injected
Middleware not executed because it's placed after route handlers, or response is not text/html.
fix
Move middleware before all routes. Check Content-Type header.
Cannot find module 'browser-sync'
browser-sync is not installed.
fix
npm install browser-sync --save-dev
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
browser-syncrequiredpeer dependency: requires browser-sync >=2.0.0
Agent activity
14 hits · last 30 days
node
10
Amazon
3
OpenAI (training)
1
Resources
connect-browser-sync — npm install connect-browser-sync · libregistry