npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2026 – Pkg Stats / Ryan Hefner

troj3n

v0.0.12

Published

πŸ›‘οΈ Antivirus for Node.js projects - Scan for infected files and malicious/vulnerable packages with real-time protection

Readme

πŸ›‘οΈ Troj3n

Antivirus for Node.js projects

Scan for infected files and malicious/vulnerable packages with real-time protection

npm version npm downloads License: MIT TypeScript Node.js


✨ Features

  • πŸ” File Scanning - Detect infected files with suspicious patterns, obfuscated code, and malware
  • πŸ“¦ Package Scanning - Identify malicious and vulnerable npm packages
  • ⏱️ Periodic Scanning - Automatic scans every 5 minutes (configurable)
  • 🎯 TypeScript Support - Full type safety with excellent IDE integration
  • 🚨 Automated Rules - Delete infected files, update packages, or stop servers automatically
  • πŸ“Š Detailed Reporting - Get comprehensive scan results with severity levels
  • 🎨 Beautiful Logging - Colored console output for easy monitoring

πŸ“¦ Installation

npm install troj3n

πŸš€ Quick Start

JavaScript

import troj3n from "troj3n";

// Run with default options (scans files and packages every 5 minutes)
const { results, stop } = await troj3n();

// Stop periodic scanning when needed
stop();

TypeScript

import troj3n, { type Troj3nOptions, type ScanResults } from "troj3n";

// Run with default options
const { results, stop } = await troj3n();

// Stop periodic scanning when needed
stop();

πŸ“– Usage

Basic Usage

import troj3n from "troj3n";

// Default scan (files + packages, logging enabled, scans every 5 minutes)
const { results, stop } = await troj3n();

// Stop periodic scanning
stop();

Periodic Scanning

By default, troj3n runs scans every 5 minutes. You can customize the interval:

// Scan every 30 seconds
const { results, stop } = await troj3n({
  scanEvery: "30s",
});

// Scan every 10 minutes
const { results, stop } = await troj3n({
  scanEvery: "10m",
});

// Scan every hour
const { results, stop } = await troj3n({
  scanEvery: "1h",
});

// Run once (disable periodic scanning)
const results = await troj3n({
  scanEvery: "",
});

Time Format: Use a number followed by a unit:

  • s = seconds (e.g., "30s")
  • m = minutes (e.g., "5m")
  • h = hours (e.g., "1h")

Custom Scopes

// Scan only files
await troj3n({
  scopes: ["files"],
});

// Scan only packages
await troj3n({
  scopes: ["packages"],
});

// Scan both (default)
await troj3n({
  scopes: ["files", "packages"],
});

Disable Logging

const { results, stop } = await troj3n({
  logging: false,
});

Execute Rules

// Delete infected files automatically
const { results, stop } = await troj3n({
  rules: {
    deleteInfectedFiles: true,
  },
});

// Delete infected files and stop the server
const { results, stop } = await troj3n({
  rules: {
    deleteInfectedFilesAndStop: true,
  },
});

// Update/fix packages and stop the server
const { results, stop } = await troj3n({
  rules: {
    updatePackagesAndStop: true,
  },
});

Complete Example

JavaScript

import troj3n from "troj3n";

// Periodic scanning (default: every 5 minutes)
const { results, stop } = await troj3n({
  scopes: ["files", "packages"],
  logging: true,
  scanEvery: "5m", // or "30s", "1h", etc.
  rules: {
    deleteInfectedFiles: false,
    deleteInfectedFilesAndStop: false,
    updatePackagesAndStop: false,
  },
});

console.log("Infected files:", results.infectedFiles);
console.log("Vulnerable packages:", results.vulnerablePackages);
console.log("Malicious packages:", results.maliciousPackages);

// Stop periodic scanning when needed
stop();

TypeScript

import troj3n, {
  type Troj3nOptions,
  type ScanResults,
  type InfectedFile,
  type VulnerablePackage,
  type MaliciousPackage,
} from "troj3n";

const options: Troj3nOptions = {
  scopes: ["files", "packages"],
  logging: true,
  scanEvery: "5m", // Periodic scanning every 5 minutes
  rules: {
    deleteInfectedFiles: false,
    deleteInfectedFilesAndStop: false,
    updatePackagesAndStop: false,
  },
};

// With periodic scanning enabled, returns { results, stop }
const { results, stop } = await troj3n(options);

// TypeScript provides full type safety and autocomplete
results.infectedFiles.forEach((file: InfectedFile) => {
  console.log(`File: ${file.path}, Severity: ${file.severity}`);
  file.issues.forEach((issue) => console.log(`  - ${issue}`));
});

results.vulnerablePackages.forEach((pkg: VulnerablePackage) => {
  console.log(`${pkg.name}@${pkg.version}: ${pkg.vulnerability}`);
});

// Stop periodic scanning
stop();

πŸ“š API Reference

troj3n(options)

Parameters

  • options (Troj3nOptions, optional)
    • scopes (ScanScope[], optional): Scopes to scan
      • 'files': Scan for infected files in the project
      • 'packages': Scan for malicious/vulnerable packages
      • Default: ['files', 'packages']
    • logging (boolean, optional): Enable/disable logging
      • Default: true
    • rules (Rules, optional): Rules to execute
      • deleteInfectedFiles (boolean, default: false): Delete infected files
      • deleteInfectedFilesAndStop (boolean, default: false): Delete infected files and stop the server
      • updatePackagesAndStop (boolean, default: false): Update/fix npm packages and stop the server
    • scanEvery (string, optional): Run scans periodically at the specified interval
      • Format: number + unit (s=seconds, m=minutes, h=hours)
      • Examples: "5m", "30s", "1h", "10m"
      • Default: "5m" (scans every 5 minutes)
      • Set to empty string "" to disable periodic scanning (run once)

Returns

  • If scanEvery is set (default: "5m"): Promise<{ results: ScanResults; stop: () => void }>
    • results: Scan results object
    • stop: Function to stop periodic scanning
  • If scanEvery is empty/disabled: Promise<ScanResults>

ScanResults - Object containing:

  • infectedFiles (InfectedFile[]): List of infected files found
    • path (string): Full path to the infected file
    • issues (string[]): List of detected issues
    • severity ('low' | 'medium' | 'high'): Severity level
  • vulnerablePackages (VulnerablePackage[]): List of vulnerable packages found
    • name (string): Package name
    • version (string): Package version
    • vulnerability (string, optional): Description of the vulnerability
    • severity (string, optional): Severity of the vulnerability
  • maliciousPackages (MaliciousPackage[]): List of malicious packages found
    • name (string): Package name
    • version (string): Package version

TypeScript Types

All types are exported for use in TypeScript projects:

import type {
  Troj3nOptions,
  ScanResults,
  InfectedFile,
  VulnerablePackage,
  MaliciousPackage,
  Rules,
  ScanScope,
  Severity,
} from "troj3n";

πŸ” What Gets Scanned?

File Scanning

Scans JavaScript/TypeScript files for:

  • βœ… Suspicious code patterns (eval, Function constructor, etc.)
  • βœ… Obfuscated code detection
  • βœ… Base64 encoded suspicious content
  • βœ… Malicious network requests
  • βœ… File system manipulation attempts
  • βœ… Process execution attempts

Package Scanning

Scans npm packages for:

  • βœ… Known malicious packages
  • βœ… Vulnerable packages (using npm audit)
  • βœ… Suspicious package names
  • βœ… Typosquatting patterns

βš™οΈ Default Behavior

  • Scopes: Scans both files and packages by default
  • Logging: Enabled by default
  • Rules: All rules are disabled by default (set to false)
  • Periodic Scanning: Enabled by default, scans every 5 minutes (scanEvery: "5m")

πŸ’» TypeScript Support

Troj3n is written in TypeScript and provides full type definitions. When using TypeScript, you'll get:

  • βœ… Full type safety - All parameters and return values are typed
  • βœ… IntelliSense support - Autocomplete for all options and properties
  • βœ… Hover documentation - JSDoc comments appear when hovering over functions and types
  • βœ… Type checking - Catch errors at compile time

The package works seamlessly with both JavaScript and TypeScript projects.

πŸ› οΈ Development

To build the project from source:

# Install dependencies
npm install

# Build TypeScript
npm run build

πŸ“‹ Requirements

  • Node.js >= 14.0.0
  • npm (for package vulnerability scanning)

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

MIT License - see LICENSE file for details.

⭐ Show Your Support

If you find this project helpful, please consider giving it a star on GitHub!