0.2.0 • Published 2 years ago

second-console v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

second console · npm install size dependencies license

External nodejs console for you outputs.

example

Quick Quick Start (no install)

npx second-console

Copy/paste the code-snippet and you are already connected.

Quick Start

npm i second-console
const Console = require("second-console");
const console = new Console();
console.log(["Hello from remote!"]);

This will automatically create a new terminal window for you and reconnect to the same window. If you want to start the remote console yourself (e.g. in your IDE), just use npx second-console with the same parameters.

API

The created console has the same interface as the default nodejs console.

const Console = require("second-console");

const remoteConsole = new Console({
  // use either seed, path OR port
  seed: "<SEED>", // will create an IPC path at the correct location for you – recommended
  path: "/<MY>/<PATH>", // use with caution
  port: 8090, // use when seed is not working or you want to connect to a remote host

  // when using port, you can define a remote host by IP
  host: "192.168.178.22",

  //these will be passed to the remote consoled if open by your process
  reconnect: true, // when set to false, the remote console will not allow reconnections
  wait: true, // when wait and reconnect are set to false the remote console will terminate with you process
  clearConsole: false, // when set to true, the console will be cleared after every reconnect
});

multiple inputs and outputs

So pratically multiple processes could share multiple remote consoles, where for example P1 and P2 both write to C1 and C2. This could come in handy when you're running some network of workers and have multiple reporting channels.

Although this works you could encounter that some issues when two or more workers try to write big outputs on the same console. Since the transmission is chunked and not properly ordered on the remote console, this could result in overlapping messages.

Known issues

  • Windows is making problems when we use the IPC channels for connection. If you're having troubles try using npx second-console -p 9098 instead.
  • WSL in itself works but is not (yet) intercomatible with Windows consoles. Maybe the external console needs to be started with 0.0.0.0 for host. IPC Channels between WSL and Windows is probably never going to work (at least in the forseeable future).
  • WSL is not (yet) supporting automatic start of an external console. This is probably fixable.

Use-cases

Here are some use-cases I had in mind. (howtos coming soon)

Something is spaming your stdout

Haven't we all been there when you just want to debug some code with console.log(whyAreYouFalse) and winston or some other module is just spaming logs.

At this point you can:

  • disable the spaming code (good luck finding it)
  • console.log("\n\n\n\n\n\n", { hahaFindMe }, "\n\n\n\n\n\n\n\n")
  • second-console

Combining outputs from a worker network

When working with a network of workers it can be handy to have them write their results or issues to a common console, especially when you're running over 200 in a LAN.

console.log/stdout is disabled

Been there, done that – waisting not just time but also my precious sanity.

developing nodejs in docker (or over physical network)

Yeah, you can docker logs -f myCuntainer but you don't have time to type that every time!

outsource debug logs

Just outsource these badboys to an external console and have a nice day.

using in production

Could you? -> Sure! Should you? -> Probably not

(maybe) coming features

  • browser support
  • input support
  • inject external console to modules via wrap function
  • close() function
  • (alpine) docker image with injected external console

Contribution

Open for suggestions, issues and PRs.

ToDos

  • tests
  • closing testing on all platforms
  • test over the network
0.2.0

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago