A powerful Node.js module for seamless interaction with MikroTik RouterOS API, supporting both plain text (port 8728) and encrypted (port 8729) connections. π
- π¦ Package Configuration - Fixed npm README detection issue
- π§ Publishing - Enhanced package.json metadata for better npm registry recognition
- π Comprehensive Command Reference - Complete RouterOS API command reference in
Refrence.js
- π§ͺ Production Example - Enhanced
app.js
with advanced error handling and connectivity testing - π§ Improved Buffer Management - Enhanced buffer handling for better performance
- π Enhanced Documentation - Better examples and troubleshooting guides
- π¬ Community Support - Telegram support group for community assistance
- π Secure connections via plain text and TLS encryption
- π Full support for RouterOS API protocol encoding/decoding
- β‘ Modern Promise-based API implementation
- π οΈ Comprehensive MikroTik API command helpers
- π Robust error handling mechanism
- π Built-in debug mode for troubleshooting
- π¦ Lightweight with minimal dependencies
npm install ros-client
const RouterOSClient = require("ros-client");
// Create API client instance
const api = new RouterOSClient({
host: "192.168.88.1",
username: "admin",
password: "your-password",
port: 8728, // Use 8729 for TLS
tls: false, // Set to true for encrypted connection
});
async function example() {
try {
await api.connect();
console.log("β
Connected successfully!");
// Get system identity
const identity = await api.send(["/system/identity/print"]);
console.log("π₯οΈ Router identity:", identity);
// Get all interfaces
const interfaces = await api.send(["/interface/print"]);
console.log("π Interfaces:", interfaces);
await api.close();
} catch (err) {
console.error("β Error:", err.message);
}
}
example();
For a comprehensive list of all available RouterOS API commands with detailed documentation, see the Refrence.js file. This file contains:
- π§ System Commands - Identity, resources, clock, logging, etc.
- π Interface Management - Ethernet, wireless, bridge, VLAN, etc.
- π IP Configuration - Addresses, routes, DNS, DHCP, firewall, etc.
- πΆ Wireless Operations - Registration, scanning, security, etc.
- π Security Features - Firewall rules, NAT, user management, etc.
- π Monitoring Tools - Traffic, queues, logs, statistics, etc.
For a production-ready example with advanced error handling and connectivity testing, see the app.js file which demonstrates:
- β Connection Testing - TCP connectivity validation
- π₯ Advanced Error Handling - Detailed error categorization and troubleshooting
- π Event Monitoring - Comprehensive event listeners
- π¨ Timeout Management - Connection and operation timeouts
- π Debug Logging - Detailed connection and operation logging
const api = new RouterOSClient({
host: "192.168.88.1", // Router IP address
username: "admin", // Username
password: "password", // Password
port: 8728, // API port (8729 for TLS)
tls: false, // TLS encryption
timeout: 10000, // Connection timeout (ms)
debug: false, // Debug output
});
Establishes and authenticates the RouterOS connection.
await api.connect();
Gracefully terminates the RouterOS connection.
await api.close();
Executes commands on the RouterOS device.
const result = await api.send(["/system/resource/print"]);
// System identity operations
const identity = await api.send(["/system/identity/print"]);
await api.send(["/system/identity/set", "=name=my-router"]);
// Resource monitoring
const resources = await api.send(["/system/resource/print"]);
// System maintenance
await api.send(["/system/reboot"]);
// Interface operations
const interfaces = await api.send(["/interface/print"]);
await api.send(["/interface/enable", "=.id=ether1"]);
// Wireless interface management
const wireless = await api.send(["/interface/wireless/print"]);
// IP address management
const addresses = await api.send(["/ip/address/print"]);
await api.send([
"/ip/address/add",
"=address=192.168.1.1/24",
"=interface=ether1",
]);
// DHCP server management
const leases = await api.send(["/ip/dhcp-server/lease/print"]);
The client emits these events:
connected
β - Connection establishederror
β - Error occurredclose
π - Connection terminated
api.on("connected", () => console.log("β
Connected"));
api.on("error", (err) => console.error("β Error:", err.message));
api.on("close", () => console.log("π Connection closed"));
Enable detailed logging:
const api = new RouterOSClient({
debug: true,
// other options...
});
try {
await api.connect();
const result = await api.send(["/command"]);
} catch (err) {
console.error("β Error:", err.message);
}
This project is licensed under the MIT License - see the LICENSE file for details.
We welcome contributions! Here's how:
- π Fork the repository
- πΏ Create your feature branch (
git checkout -b feature/amazing-feature
) - βοΈ Commit changes (
git commit -m 'Add amazing feature'
) - π€ Push to branch (
git push origin feature/amazing-feature
) - π« Open a Pull Request
We thank the following contributors for their valuable contributions to this project:
- mbingsdk - Update limit buffer functionality π§
- AviStudio - Command Reference (Refrence.js) documentation π
Need help or have questions? Join our community:
π² Telegram Support Group: https://t.me/ros_client
For detailed information about changes in each version, see the CHANGELOG.md file.
β Star this repository if you find it helpful!