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

mikro-routeros

v1.0.6

Published

MikroTik API (RouterOS) client for Node.js with auto-parameter detection and response parsing. Works with PPPoE, Hotspot, and more.

Readme

MikroTik API (RouterOS) Client for Node.js

Node.js client for the MikroTik RouterOS API. Simple, fast, and lightweight with automatic parameter detection and parsed responses. Ideal for PPPoE, Hotspot, Firewall, Wireless, and general RouterOS automation.

Features

  • Automatic parameter detection for RouterOS commands (query vs action)
  • Streams until !done to handle multi-packet MikroTik API responses
  • Proper error handling for !trap and !fatal
  • Parsed responses into clean JavaScript objects
  • Configurable connection timeout to prevent hanging connections
  • Covers PPPoE, Hotspot, Firewall, Wireless and more

Installation

npm install mikro-routeros

Quick start

const { RouterOSClient } = require('mikro-routeros');

async function main() {
  // Optional: Set custom timeout (30 seconds) - default is 30000ms
  const client = new RouterOSClient('192.168.88.1', 8728, 30000);
  await client.connect();
  await client.login('admin', 'password');

  const users = await client.runQuery('/ppp/secret/print', { name: 'user1' });
  console.log(users);

  await client.close();
}

main().catch(console.error);

Usage

Run tests (optional)

npm test

Library examples

const { RouterOSClient } = require('mikro-routeros');

// Examples of different timeout configurations:
// const client = new RouterOSClient('192.168.88.1'); // Default: port 8728, timeout 30s
// const client = new RouterOSClient('192.168.88.1', 8728); // Default timeout 30s
// const client = new RouterOSClient('192.168.88.1', 8728, 10000); // 10 second timeout
const client = new RouterOSClient('192.168.88.1', 8728, 30000); // 30 second timeout

await client.connect();
await client.login('admin', 'password');

// PPPoE users (query uses ?-prefixed params)
const users = await client.runQuery('/ppp/secret/print', { name: 'user1' });

// Add PPPoE secret (action uses =-prefixed params)
await client.runQuery('/ppp/secret/add', {
  name: 'newuser',
  password: 'password123',
  profile: 'default',
  service: 'pppoe'
});

// Update user
await client.runQuery('/ppp/secret/set', {
  '.id': '*123',
  password: 'newpassword'
});

// Delete user
await client.runQuery('/ppp/secret/remove', { '.id': '*123' });

// Disconnect active user
await client.runQuery('/ppp/active/remove', { '.id': '*456' });

await client.close();

More MikroTik API examples

// Firewall rules
await client.runQuery('/ip/firewall/filter/print');

// Hotspot users
await client.runQuery('/ip/hotspot/user/print');

// Wireless registration table
await client.runQuery('/interface/wireless/registration-table/print');

// Get system identity
await client.runQuery('/system/identity/print');

API reference

RouterOSClient

Constructor

new RouterOSClient(host, port = 8728, timeout = 30000)

Parameters:

  • host (string): MikroTik RouterOS IP address or hostname
  • port (number, optional): API port, default is 8728 (TCP) or 8729 (TLS)
  • timeout (number, optional): Connection timeout in milliseconds, default is 30000 (30 seconds)

Methods

  • connect() - Connect to RouterOS API (TCP)
  • login(username, password) - Authenticate with RouterOS
  • runQuery(command, params = {}) - Execute command and return parsed objects
  • close() - Close connection

TypeScript typings are included via index.d.ts.

Error handling

try {
  await client.connect();
  const result = await client.runQuery("/ppp/secret/add", {...});
} catch (error) {
  console.error("Error:", error.message);
  // Connection timeout: "Connection timeout after 30000ms"
  // RouterOS error: "RouterOS Error: failure: secret with the same name already exists"
  // Network error: "ECONNREFUSED" or "ENOTFOUND"
}

Connection timeout

If the connection takes longer than the specified timeout, the promise will reject with a timeout error:

const client = new RouterOSClient('192.168.1.1', 8728, 5000); // 5 second timeout

try {
  await client.connect();
} catch (error) {
  if (error.message.includes('Connection timeout')) {
    console.log('Connection timed out after 5 seconds');
  }
}

Test suite

The test suite demonstrates:

  1. CREATE - Add new PPPoE secret user
  2. READ - Query user by name
  3. UPDATE - Modify user password and comment
  4. DELETE - Remove user
  5. DISCONNECT - Disconnect active user and verify

Run locally:

npm start

Requirements

  • Node.js 12.0.0 or higher
  • Access to MikroTik RouterOS with API enabled

Notes:

  • RouterOS API default ports: 8728 (plain TCP), 8729 (TLS). This client uses TCP.
  • Works with RouterOS v6/v7 command paths.

Links

License

ISC