backlens 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,6 +12,10 @@ The link backlens prints carries a private token: keep it to yourself, it contro
12
12
 
13
13
  To run one exact command instead: `npx backlens -- node server.js`.
14
14
 
15
+ To keep it in the project, install it as a dev dependency with your package manager (`npm i -D backlens`, `pnpm add -D backlens`, `yarn add -D backlens`). In a pnpm or yarn workspace, use that tool: npm cannot install into a project whose package.json uses `workspace:` versions.
16
+
17
+ The dashboard uses port 7777, or the next free one if it is taken. `--port` picks one.
18
+
15
19
  ## What you get
16
20
 
17
21
  - **Routes**: every endpoint your app registers (fastify and nest report them at startup; express routes appear once called), with calls, p50 and p95, and how many database, Redis and outgoing HTTP calls each request makes.
package/bin/backlens.js CHANGED
@@ -42,19 +42,25 @@ if (testMode) await runTests();
42
42
  else await runStudio();
43
43
 
44
44
  async function runStudio() {
45
- const port = Number(flag('--port') ?? 7777);
45
+ const chosen = flag('--port');
46
+ // Without --port, a busy 7777 (another backlens, say) moves on to the next free port.
47
+ const ports = chosen ? [Number(chosen)] : Array.from({ length: 20 }, (_, i) => 7777 + i);
46
48
  let server;
47
- try {
48
- server = await startServer({
49
- port,
50
- root,
51
- token,
52
- manualArgv: command.length ? command : null,
53
- mirror: (line, stream) => process.stderr.write(`${dim('app │')} ${stream === 'sys' ? dim(line) : line}\n`),
54
- });
55
- } catch (err) {
56
- process.stderr.write(`backlens: could not open port ${port} (${err.code ?? err.message}). Try --port.\n`);
57
- process.exit(1);
49
+ for (const port of ports) {
50
+ try {
51
+ server = await startServer({
52
+ port,
53
+ root,
54
+ token,
55
+ manualArgv: command.length ? command : null,
56
+ mirror: (line, stream) => process.stderr.write(`${dim('app │')} ${stream === 'sys' ? dim(line) : line}\n`),
57
+ });
58
+ break;
59
+ } catch (err) {
60
+ if (err.code === 'EADDRINUSE' && port !== ports.at(-1)) continue;
61
+ process.stderr.write(`backlens: could not open port ${port} (${err.code ?? err.message}). Try --port.\n`);
62
+ process.exit(1);
63
+ }
58
64
  }
59
65
  const link = `http://localhost:${server.address().port}/?t=${token}`;
60
66
  process.stderr.write(`${bold('backlens')} dashboard ${bold(link)}\n${dim(' keep this link private: it controls your app. Ctrl+C stops everything.')}\n\n`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backlens",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Run your Node backend through backlens and see every request, every query, and what is wrong with them.",
5
5
  "license": "MIT",
6
6
  "type": "module",