Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
diagnostics_channel
Advanced tools
Exposes a polyfill for the Node.js module diagnostics_channel
The diagnostics_channel package is a module that provides an API for creating named channels that allow publishers and subscribers to communicate via a publish/subscribe mechanism. It is useful for diagnostics and monitoring of Node.js applications.
Creating a channel
This code demonstrates how to create a new diagnostics channel named 'my-channel'.
const diagnostics_channel = require('diagnostics_channel');
const channel = diagnostics_channel.channel('my-channel');
Publishing to a channel
This code shows how to publish a message to the 'my-channel'. The message is an object with data that subscribers can listen for.
const diagnostics_channel = require('diagnostics_channel');
const channel = diagnostics_channel.channel('my-channel');
channel.publish({ foo: 'bar' });
Subscribing to a channel
This code snippet demonstrates how to subscribe to the 'my-channel' and log the name of the channel and the message received.
const diagnostics_channel = require('diagnostics_channel');
const channel = diagnostics_channel.channel('my-channel');
channel.subscribe((message, name) => {
console.log(name, message);
});
Checking if a channel has subscribers
This code checks if the 'my-channel' has any subscribers before publishing a message to it.
const diagnostics_channel = require('diagnostics_channel');
const channel = diagnostics_channel.channel('my-channel');
if (channel.hasSubscribers) {
channel.publish({ foo: 'bar' });
}
EventEmitter3 is a high-performance event emitter. It offers similar publish/subscribe functionality but is not specifically designed for diagnostics or monitoring purposes. It is more general-purpose.
The debug package allows you to create debug instances that can be turned on and off based on environment variables. It is similar in that it is used for diagnostics, but it does not provide a channel-based publish/subscribe mechanism.
Bunyan is a JSON logging library for Node.js services. It provides detailed logs and includes mechanisms for streams and serializers. While it is used for diagnostics, it is more focused on logging than the publish/subscribe pattern.
Winston is another logging library for Node.js. Similar to Bunyan, it is used for diagnostics and monitoring but is focused on logging with multiple transports, rather than a channel-based communication system.
Exposes a polyfill for the Node.js module diagnostics_channel
.
As of now, the Node.js module diagnostics_channel
is only available in Node ^14.17.0 || >=15.1.0
.
This aim to allow using the same API on older versions of Node.
npm i diagnostics_channel
Refer to the official documentation: https://nodejs.org/api/diagnostics_channel.html
WeakReference
is not available, channels will NOT be garbage collected when no reference is held in user-land. An additional function is provided to do manual cleanup if needed: dc.deleteChannel()
. This should not be needed in a typical scenario. Only use this method if you know why you are doing it.const dc = require('diagnostics_channel');
const a = dc.channel('test');
const b = dc.channel('test');
// channel is memoized
console.log(a === b); // true
dc.deleteChannel('test');
const c = dc.channel('test');
// memoized channel was deleted and a new instance was memoized
console.log(a === c); // false
ERR_INVALID_ARG_TYPE
is not available, a simplfied copy of this error is included.triggerUncaughtException()
is not available, if an exception is thrown in a subscriber, the polyfill will instead simply re-throw the error inside a process.nextTick()
, which has a similar behavior except when the process crashes because of that exception: the crash message will point to this polyfill instead of where the error was created (ie: in the subscriber).FAQs
Exposes a polyfill for the Node.js module diagnostics_channel
The npm package diagnostics_channel receives a total of 513,670 weekly downloads. As such, diagnostics_channel popularity was classified as popular.
We found that diagnostics_channel demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.