
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
debug-better
Advanced tools
Advanced TypeScript debugging utility with filtering capabilities for Node.js and browser
A modern, TypeScript-based debugging utility with advanced filtering capabilities for Node.js and browser environments. Built as an enhanced version of the popular debug package with additional features.
npm install debug-better
import debug from 'debug-better';
const log = debug('app:server');
log('Server starting on port %d', 3000);
log('Connected to database');
Node.js:
DEBUG=* node app.js # Enable all
DEBUG=app:* node app.js # Enable app namespace
DEBUG=app:*,-app:verbose node app.js # Enable app except verbose
Browser:
localStorage.setItem('debug', 'app:*');
// Or via URL: ?debug=app:*
Full type safety and IntelliSense:
import debug, { Debugger, FilterOptions } from 'debug-better';
const log: Debugger = debug('my-app');
const filterOpts: FilterOptions = {
enabled: true,
patterns: [/^api:.*/],
exclude: ['api:debug'],
};
import debug from 'debug-better';
// Set global filter
debug.setGlobalFilter({
include: ['app:*', 'api:*'],
exclude: ['*:verbose', '*:debug'],
});
const log = debug('app:main');
log('This will be shown');
const verboseLog = debug('app:verbose');
verboseLog('This will be hidden');
import debug from 'debug-better';
debug.setGlobalFilter({
patterns: [
/^api:.*$/, // Match all api namespaces
/^app:(server|db)$/, // Match specific namespaces
],
});
import debug from 'debug-better';
debug.setGlobalFilter({
predicates: [
// Only log during business hours
(namespace: string) => {
const hour = new Date().getHours();
return hour >= 9 && hour <= 17;
},
// Only log errors and warnings
(namespace: string, ...args: any[]) => {
const msg = args[0]?.toString() || '';
return msg.includes('error') || msg.includes('warning');
},
],
});
import debug from 'debug-better';
const log = debug('app:main', {
filter: {
enabled: true,
predicates: [
(namespace, ...args) => {
// Custom logic for this instance
return args[0]?.priority === 'high';
},
],
},
});
log({ priority: 'high' }, 'Important message'); // Shown
log({ priority: 'low' }, 'Regular message'); // Hidden
Attach contextual data to debugger instances:
import debug from 'debug-better';
const log = debug('api:user', {
metadata: {
service: 'user-service',
version: '1.0.0',
},
});
log.setMetadata('requestId', '12345');
log('Processing request');
console.log(log.getMetadata('service')); // 'user-service'
import debug from 'debug-better';
// Add custom formatter
debug.formatters.j = (v: any) => {
return JSON.stringify(v, null, 2);
};
const log = debug('app');
log('Config: %j', { port: 3000, host: 'localhost' });
Create sub-namespaces:
import debug from 'debug-better';
const app = debug('app');
const server = app.extend('server');
const db = app.extend('db');
app('Application started'); // app
server('Server listening'); // app:server
db('Connected to database'); // app:db
import debug from 'debug-better';
const log = debug('app', {
useColors: true,
hideDate: false,
metadata: { environment: 'production' },
log: (...args) => {
// Custom log function
console.log('[CUSTOM]', ...args);
},
});
debug(namespace: string, options?: DebugOptions): Debugger
namespace: String identifier for the debugger instanceuseColors: Enable/disable colors (default: auto-detected)hideDate: Hide timestamp in outputlog: Custom log functionfilter: Instance-specific filter optionsmetadata: Additional contextual datalog(...args): Log a messageextend(namespace, delimiter?): Create a sub-debuggersetFilter(filter): Update filter optionssetMetadata(key, value): Set metadatagetMetadata(key): Get metadatanamespace: The namespace stringenabled: Whether this debugger is enableduseColors: Whether colors are usedcolor: Assigned colordiff: Time difference from previous logdebug.enable(namespaces: string): void
debug.disable(): string
debug.enabled(name: string): boolean
debug.setGlobalFilter(filter: FilterOptions): void
debug.getGlobalFilter(): FilterOptions
interface FilterOptions {
enabled?: boolean;
patterns?: RegExp[];
predicates?: FilterPredicate[];
include?: string[];
exclude?: string[];
tags?: string[];
minLevel?: number;
maxLevel?: number;
}
DEBUG: Enable namespaces (e.g., DEBUG=app:*)DEBUG_COLORS: Force colors on/offDEBUG_HIDE_DATE: Hide timestampsDEBUG_SHOW_HIDDEN: Show hidden properties in objectsIn browser environments, you can:
localStorage.setItem('debug', 'app:*')?debug=app:*debug.enable('app:*')import debug from 'debug-better';
import express from 'express';
const app = express();
const log = debug('server');
const reqLog = debug('server:request');
const errLog = debug('server:error');
app.use((req, res, next) => {
reqLog('%s %s', req.method, req.url);
next();
});
app.get('/', (req, res) => {
log('Handling root request');
res.send('Hello World');
});
app.use((err, req, res, next) => {
errLog('Error: %O', err);
res.status(500).send('Internal Server Error');
});
const PORT = 3000;
app.listen(PORT, () => {
log('Server started on port %d', PORT);
});
import debug from 'debug-better';
// Only log errors and warnings in production
if (process.env.NODE_ENV === 'production') {
debug.setGlobalFilter({
predicates: [
(namespace, ...args) => {
const msg = JSON.stringify(args);
return msg.includes('error') || msg.includes('warn');
},
],
});
}
const log = debug('service:main');
const errorLog = debug('service:error');
log('Service starting...'); // Hidden in production
errorLog('Critical error occurred!'); // Always shown
debugdebug-better is designed to be a drop-in replacement for the debug package:
// Before
const debug = require('debug');
const log = debug('app');
// After
import debug from 'debug-better';
const log = debug('app');
All existing functionality is preserved, with additional features available when needed.
debug-better is designed with performance in mind:
ms for time formattingMIT © Your Name
Contributions are welcome! Please read our contributing guidelines and code of conduct.
Inspired by the excellent debug package by TJ Holowaychuk and contributors.
debugFAQs
Advanced TypeScript debugging utility with filtering capabilities for Node.js and browser
We found that debug-better demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.