Node JS
How to instrument Tailed from Node with just three lines of code.
Setup
Install the @tailedapp/nodejs-lib npm package:
npm i @tailedapp/nodejs-libBasic Usage
You will need to create a new ConsoleSession and then start it:
// Two of the magic lines of code..
const session = new ConsoleSession();
await session.Start();
console.log('This will be streamed to tailed.live');
// The last one!
session.Stop();
console.log('This will not be streamed to tailed.live');Choose the right point at which to start the ConsoleSession. For example, if you're asking the user for credentials or a connection string, you'll want to start the session after that point so you don't stream those details to everyone viewing the session.
Any logging framework that has a console output can be used together with the above configuration code.
Default Colorization
The following default color rules apply:
console.infowill write content with a green color;console.warnwill write content with a yellow color;console.errorwill write content with a red color;stderr.writewill write content with a red color.In all other cases, the colors will be the defaults.
Further colorization can be applied using NPM packages such as chalk.
Customization Options
The constructor on the ConsoleSession allows you to specify a custom hostname to use in the session URL (instead of tailed.live).
Last updated