An LXRAY report in a terminal is useful to an administrator. But when you run a monitoring console, a managed-services portal or the admin side of an application, you want server health inside the application itself: a score, the issues to fix, an alert when things get worse. That is what the official npm package @ejouan/lxray is for.
For this article I built a small test application, "Fleet Health", with Express and the package installed from npm. The screenshots come from a test server: its name is replaced with "test-server-01", the exact kernel version is blurred, and the audit is limited to system, CPU, disks, kernel and logs.
1. Install
The package has no dependencies and works with Node.js 18 or later:
npm install @ejouan/lxray
LXRAY must be on the audited server. It installs from the signed repository (apt install lxray or dnf install lxray). For a container without root, the package can also install a copy in the user's folder, after checking the GPG signature.
2. The first audit, in four lines
const lxray = require('@ejouan/lxray');
const { summary } = await lxray.audit({ profile: 'standard' });
console.log(`${summary.hostname}: ${summary.score}/100 (${summary.grade})`);
for (const p of summary.issues) console.log(`[${p.severity}] ${p.title} -> ${p.fix}`);
summary holds the score, the letter grade, the verdict, the number of findings per severity (critical, warning, info, ok) and the issues to fix, most serious first. The full report is in result.report. HTML, Markdown and text versions come with formats: ['json', 'html', 'md', 'txt'].
3. A "server health" page in the application
On the server, an Express route returns the summary; in the browser, the interface displays it. The browser never runs LXRAY itself.
app.get('/api/summary', requireAdmin, async (req, res, next) => {
try {
const r = await lxray.audit({ profile: 'quick', formats: ['json', 'html'] });
res.json({ summary: r.summary, check: lxray.evaluate(r, { maxCritical: 0, warnScore: 80 }) });
} catch (e) { next(e); }
});

lxray.evaluate() turns the report into a monitoring state, like a Nagios or Zabbix check: OK, WARNING or CRITICAL, with exit code 0, 1 or 2. Thresholds are yours: minimum score, number of critical findings allowed, accepted risks to ignore.
4. Live progress
A full audit takes 30 seconds to 2 minutes. With the onLog option, every step of LXRAY arrives as it happens. Here it goes to the browser through Server-Sent Events:
app.get('/api/audit-stream', requireAdmin, async (req, res) => {
res.writeHead(200, { 'Content-Type': 'text/event-stream' });
const send = (ev, data) => res.write(`event: ${ev}\ndata: ${JSON.stringify(data)}\n\n`);
const r = await lxray.audit({ profile: 'quick', onLog: (line) => send('log', line) });
send('done', r.summary);
res.end();
});

5. The full report
The same result carries LXRAY's printable HTML report. Serve it as is, with a security policy that isolates it from the rest of the application:
app.get('/report', requireAdmin, (req, res) => {
res.set('Content-Security-Policy', "sandbox allow-scripts; default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'");
res.type('html').send(latest.html);
});

6. Prometheus and Grafana
One line exposes the metrics of one server or a whole fleet: score, findings per severity, partial or complete audit, duration, report date.
app.get('/metrics', requireMetrics, (req, res) => {
res.type('text/plain; version=0.0.4').send(lxray.toPrometheus(latest, { labels: { env: 'prod' } }));
});

7. Root access without giving root to the application
Without root, LXRAY reads what the application's account can read. The report says so ("partial") and lists the checks it could not evaluate: that is the "partial" badge in the screenshots. Installing an npm package never grants root, by design. The administrator grants it once, narrowly: npx lxray-setup-root prints the commands to run, without running anything. Then:
lxray.requestRootAudit()asks the system for a complete audit, which runs it as root;lxray.readLatest()instantly reads the newest root audit, made automatically every hour.
The application itself never has root.
8. A whole fleet of servers
The same package audits other machines over SSH, several in parallel. An unreachable server never blocks the others:
const results = await lxray.auditFleet([
{ host: 'web01.example', user: 'lxray', identityFile: '/etc/app/keys/lxray' },
{ host: 'db01.example', user: 'lxray', identityFile: '/etc/app/keys/lxray' },
{ local: true }
], { mode: 'latest', concurrency: 4 });
For tracking over time, lxray.compare(previous, current) gives the score change, the new issues and the resolved ones.
Takeaways
- One
npm install, no dependencies, and the health of a Linux server reaches your application in one line. - Keep every diagnostic route behind your own authentication: a report describes the inside of a server.
- The full documentation, with twelve scenarios (Express, Next.js, NestJS, Fastify, Slack alerts, managed-services portal, pre-deployment gate…), is on the package's npm page.
A bug, a question, a distribution giving an odd result? Write to me at ej@eljouan.com with the package and LXRAY versions. Every message is read.