Optional
[captureThe login event name
The callback called on successful login
Register a listener called on successful logout.
The logout event name.
The callback called on successful logout.
Register a listener called on session expiration.
The session expiration event name.
The callback called on session expiration.
Register a listener called on session restoration after a silent login.
The session restoration event name.
The callback called on successful session restore.
Register a listener called on error, with an error identifier and description.
The error event name.
The callback called on error.
Register a listener called on session extension.
The session extension event name.
The callback called on session extension.
Register a listener called when a timeout is set for a session event with the timeout handle.
The timeout set event name.
The callback called when setting a timeout.
Register a listener called when a new refresh token is issued for the session.
The new refresh token issued event name.
The callback called when a new refresh token is issued.
Register a listener called when new tokens are issued for the session.
The new tokens issued event name.
The callback called when new tokens are issued.
Register a listener called when auth state information is available during authentication.
The auth state event name.
The callback called when auth state information is available.
Returns an array listing the events for which the emitter has registered
listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
Returns the number of listeners listening for the event named eventName
.
If listener
is provided, it will return how many times the listener is found
in the list of the listeners of the event.
The name of the event being listened for
Optional
listener: FunctionThe event handler function
Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
Unegister a listener called on successful login with the logged in WebID.
The login event name.
The callback to unregister.
Unegister a listener called on successful logout.
The logout event name.
The callback to unregister.
Unegister a listener called on session expiration.
The session expiration event name.
The callback to unregister.
Unegister a listener called on session restoration after a silent login.
The session restoration event name.
The callback to unregister.
Unegister a listener called on error, with an error identifier and description.
The error event name.
The callback to unregister.
Unegister a listener called on session extension.
The session extension event name.
The callback to unregister.
Unegister a listener called when a timeout is set for a session event.
The timeout set event name.
The callback called when next setting a timeout.
Unegister a listener called when a new refresh token is issued.
The new refresh token issued event name.
The callback called next time a new refresh token is issued.
Unegister a listener called when new tokens are issued.
The new tokens issued event name.
The callback called next time new tokens are issued.
Unregister a listener called when auth state information is available.
The auth state event name.
The callback to unregister.
Register a listener called on successful login.
The login event name
The callback called on successful login
Register a listener called on successful logout.
The logout event name.
The callback called on successful logout.
Register a listener called on session expiration.
The session expiration event name.
The callback called on session expiration.
Register a listener called on session restoration after a silent login.
The session restoration event name.
The callback called on successful session restore.
Register a listener called on error, with an error identifier and description.
The error event name.
The callback called on error.
Register a listener called on session extension.
The session extension event name.
The callback called on session extension.
Register a listener called when a timeout is set for a session event with the timeout handle.
The timeout set event name.
The callback called when setting a timeout.
Register a listener called when a new refresh token is issued for the session.
The new refresh token issued event name.
The callback called when a new refresh token is issued.
Register a listener called when new tokens are issued for the session.
The new tokens issued event name.
The callback called when new tokens are issued.
Register a listener called when auth state information is available during authentication.
The auth state event name.
The callback called when auth state information is available.
Register a listener called on the next successful login with the logged in WebID.
The login event name.
The callback called on the next successful login.
Register a listener called on the next successful logout.
The logout event name.
The callback called on the next successful logout.
Register a listener called on the next session expiration.
The session expiration event name.
The callback called on the next session expiration.
Register a listener called on the next session restoration after a silent login.
The session restoration event name.
The callback called on the next successful session restore.
Register a listener called on the next error, with an error identifier and description.
The error event name.
The callback called on the next error.
Register a listener called on the next session extension.
The session extension event name.
The callback called on the next session extension.
Register a listener called the next time a timeout is set for a session event with the timeout handle.
The timeout set event name.
The callback called when next setting a timeout.
Register a listener called the next time a new refresh token is issued for the session.
The new refresh token issued event name.
The callback called next time a new refresh token is issued.
Register a listener called the next time auth state information is available during authentication.
The auth state event name.
The callback called next time auth state information is available.
Adds the listener
function to the beginning of the listeners array for the
event named eventName
. No checks are made to see if the listener
has
already been added. Multiple calls passing the same combination of eventName
and listener
will result in the listener
being added, and called, multiple times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
The callback function
Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
The callback function
Returns a copy of the array of listeners for the event named eventName
,
including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
particularly when the EventEmitter
instance was created by some other
component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolUnegister a listener called on successful login with the logged in WebID.
The login event name.
The callback to unregister.
Unegister a listener called on successful logout.
The logout event name.
The callback to unregister.
Unegister a listener called on session expiration.
The session expiration event name.
The callback to unregister.
Unegister a listener called on session restoration after a silent login.
The session restoration event name.
The callback to unregister.
Unegister a listener called on error, with an error identifier and description.
The error event name.
The callback to unregister.
Unegister a listener called on session extension.
The session extension event name.
The callback to unregister.
Unegister a listener called when a timeout is set for a session event.
The timeout set event name.
The callback called when next setting a timeout.
Unegister a listener called when a new refresh token is issued.
The new refresh token issued event name.
The callback called next time a new refresh token is issued.
Unegister a listener called when new tokens are issued.
The new tokens issued event name.
The callback called next time new tokens are issued.
Unregister a listener called when auth state information is available.
The auth state event name.
The callback to unregister.
By default EventEmitter
s will print a warning if more than 10
listeners are
added for a particular event. This is a useful default that helps finding
memory leaks. The emitter.setMaxListeners()
method allows the limit to be
modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
Register a listener called on successful login.