Package Exports
- @maniwrld/marzjs
- @maniwrld/marzjs/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@maniwrld/marzjs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
π MarzJS
A powerful and easy-to-use Node.js client for interacting with the Marzban Panel API.
π Features
- π‘ Full API coverage for Marzban
- π Secure authentication (token-based and credentials-based)
- π Comprehensive method support
- π§© Easy-to-use interface
- π WebSocket log streaming
- β»οΈ Automatic retry mechanism for network requests
π¦ Installation
npm install @maniwrld/marzjsπ Quick Start
Authentication Methods
const MarzbanAPI = require('@maniwrld/marzjs');
// Option 1: Authentication with username and password
const client = new MarzbanAPI({
domain: 'your-marzban-server.com',
port: 8000,
username: 'admin',
password: 'your-password',
ssl: true // Optional: use HTTPS/WSS
});
// Option 2: Authentication with token (skip credentials)
const clientWithToken = new MarzbanAPI({
domain: 'your-marzban-server.com',
port: 8000,
token: 'your-access-token',
ssl: true // Optional: use HTTPS/WSS
});
// Option 3: Customize retry and timeout settings
const robustClient = new MarzbanAPI({
domain: 'your-marzban-server.com',
port: 8000,
username: 'admin',
password: 'your-password',
ssl: true,
timeout: 15000, // Custom timeout (ms)
retryDelay: 2000, // Delay between retries (ms)
maxRetries: 5 // Maximum number of retries
});π Key Methods
π€ Admin Operations
getCurrentAdmin(): Get current admin detailscreateAdmin(adminData): Create a new adminmodifyAdmin(username, adminData): Update admin informationremoveAdmin(username): Delete an admingetAdmins(params): Retrieve list of admins
π User Management
addUser(): Create a new usergetUser(): Retrieve user detailsmodifyUser(): Update user informationremoveUser(): Delete a usergetUserUsage(): Check user's data usageresetUserDataUsage(): Reset a user's data usagerevokeUserSubscription(): Revoke user's subscriptiongetUsers(): Retrieve list of all usersresetUsersDataUsage(): Reset data usage for all userssetUserOwner(): Set a user's admin parentgetExpiredUsers(): Retrieve list of expired usersdeleteExpiredUsers(): Delete expired users
π Subscription Handling (Under user class)
getUserSubscription(token): Get subscription detailsgetUserSubscriptionInfo(token): Get detailed subscription informationgetUserSubscriptionUsage(token): Check subscription usagegetUserSubscriptionWithClientType(token, clientType): Get subscription for specific client type
π Template Management
getUserTemplates(): Get list of user templatesaddUserTemplate(templateData): Create a new user templategetUserTemplateById(template_id): Get template by IDmodifyUserTemplate(id, templateData): Update a user templateremoveUserTemplate(id): Delete a user template
π₯ Node Operations
getNodeSettings(): Retrieve node settingsaddNode(nodeData): Add a new nodegetNode(nodeId): Get details of a specific nodemodifyNode(nodeId, nodeData): Update node informationremoveNode(nodeId): Delete a nodegetNodes(params): Retrieve list of nodesreconnectNode(nodeId): Reconnect a nodegetNodesUsage(): Retrieve usage statistics for nodes
π System Insights
getSystemStats(): Fetch system statisticsgetInbounds(): Get available inboundsgetHosts(): Retrieve host informationmodifyHosts(hostData): Update host configuration
π» Core System Management
getCoreStats(): Get core system statisticsrestartCore(): Restart the core systemgetCoreConfig(): Retrieve core configurationmodifyCoreConfig(configData): Modify core configuration
π WebSocket Logging
client.connectToLogs({
interval: 1, // Log polling interval
onMessage: (logData) => {
console.log('Received log:', logData);
},
onError: (error) => {
console.error('WebSocket error:', error);
}
});
// Don't forget to disconnect when done
client.disconnectFromLogs();π§ Configuration Options
When initializing the MarzJS client, you can customize the following parameters:
domain: Your Marzban server domain (required)port: Server port (required)username: Admin username (optional if using token)password: Admin password (optional if using token)token: Authentication token (optional alternative to username/password)ssl: Use HTTPS/WSS (default: false)timeout: Request timeout in milliseconds (default: 10000)retryDelay: Delay between retry attempts in milliseconds (default: 1000)maxRetries: Maximum number of retry attempts (default: 3)
π Troubleshooting
Common Connection Issues
Authentication Failures
- Symptom: Repeated 401 or 403 errors
- Possible Causes:
- Incorrect domain or port
- Expired or invalid credentials
- Network restrictions
- Solutions:
// Double-check your connection parameters const marzban = new MarzbanAPI({ domain: 'correct-domain.com', port: 8080, username: 'admin', password: 'correct-password', ssl: true });
Network Timeout Errors
- Symptom: Requests timing out frequently
- Possible Causes:
- Slow network connection
- Server under heavy load
- Firewall restrictions
- Solutions:
// Increase timeout and retry settings const robustClient = new MarzbanAPI({ domain: 'example.com', timeout: 30000, // Increased to 30 seconds retryDelay: 3000, // 3 seconds between retries maxRetries: 5 // More retry attempts });
WebSocket Connection Problems
- Symptom: Unable to establish log streaming connection
- Possible Causes:
- Incorrect SSL configuration
- Firewall blocking WebSocket
- Incorrect API permissions
- Solutions:
try { client.connectToLogs({ interval: 2, // Adjust polling interval onError: (error) => { console.error('Detailed WebSocket error:', error); // Implement reconnection logic if needed } }); } catch (error) { console.error('Log connection initialization error:', error); }
Debugging Tips
- Enable Verbose Logging: Use Node.js debugging tools or environment variables to get more detailed error information
- Check Marzban Panel Logs: Cross-reference with server-side logs for comprehensive troubleshooting
- Verify API Endpoint: Ensure your Marzban Panel is running and accessible
Getting Help
- GitHub Issues: Open an issue with detailed error logs
- Community Support: Check project discussions for known issues
- Provide Detailed Information:
- Node.js version
- MarzJS version
- Complete error message
- Minimal reproducible example
π‘ Examples
π» Get current admin
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const response = await marzban.admin.getCurrentAdmin();
console.log(response)
} catch (error) {
console.error(`Error getting current admin:`, error.message);
}
})();π» Create a admin
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const admin_data = {
"username": "chilladmin",
"is_sudo": true,
"telegram_id": 0,
"discord_webhook": "",
"password": "securepasswordhopefully"
}
const response = await marzban.admin.createAdmin(admin_data);
console.log(response)
} catch (error) {
console.error(`Error creating admin:`, error.message);
}
})();π» Modify a admin
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const target_admin = "chilladmin";
const admin_data = {
"password": "hopefullysecurethistime",
"is_sudo": true,
"telegram_id": 0,
"discord_webhook": ""
}
const response = await marzban.admin.modifyAdmin(target_admin, admin_data);
console.log(response)
} catch (error) {
console.error(`Error modifying admin:`, error.message);
}
})();π» Remove a admin
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const target_admin = "notchilladmin";
const response = await marzban.admin.removeAdmin(target_admin);
console.log(response)
} catch (error) {
console.error(`Error removing admin:`, error.message);
}
})();π» Get admins
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const response = await marzban.admin.getAdmins();
console.log(response)
} catch (error) {
console.error(`Error listing admins:`, error.message);
}
})();π» User creation
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const userData = {
status: "active",
username: "JohnDoe",
note: "Created using marzban api",
proxies: {
vmess: {}
},
data_limit: 0,
expire: 0,
data_limit_reset_strategy: "no_reset",
inbounds: {
vmess: ["VMess TCP"]
}
};
const response = await marzban.user.addUser(userData);
console.log('User added successfully:', response);
} catch (error) {
console.error('Error adding user:', error.message);
}
})();
π» Fetching user information
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const username = 'user1234';
const response = await marzban.user.getUser(username);
console.log('User information retrieved successfully:', response);
} catch (error) {
console.error('Error retrieving user information:', error.message);
}
})();π» Modifying user
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const username = 'user1234';
const userData = {
proxies: {
vmess: {
id: '35e4e39c-7d5c-4f4b-8b71-558e4f37ff53'
},
vless: {}
},
inbounds: {
vmess: ['VMess TCP', 'VMess Websocket'],
vless: ['VLESS TCP REALITY', 'VLESS GRPC REALITY']
},
expire: 0,
data_limit: 0,
data_limit_reset_strategy: 'no_reset',
status: 'active',
note: 'Updated note',
on_hold_timeout: '2023-11-03T20:30:00',
on_hold_expire_duration: 0
};
const response = await marzban.user.modifyUser(username, userData);
console.log('User modified successfully:', response);
} catch (error) {
console.error('Error modifying user:', error.message);
}
})();π» Deleting user
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const username = 'user1234';
const response = await marzban.user.removeUser(username);
console.log('User removed successfully:', response);
} catch (error) {
console.error('Error removing user:', error.message);
}
})();π» Get user usage
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const username = 'user1234';
const response = await marzban.user.getUserUsage(username);
console.log(response)
} catch (error) {
console.error(`Error getting user's usage:`, error.message);
}
})();π» Reset User Data Usage
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const username = 'user1234';
const response = await marzban.user.resetUserDataUsage(username);
console.log(response)
} catch (error) {
console.error(`Error resetting user's usage:`, error.message);
}
})();π» Revoke User Subscription
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const username = 'user1234';
const response = await marzban.user.revokeUserSubscription(username);
console.log(response)
} catch (error) {
console.error(`Error revoking user's subscription:`, error.message);
}
})();π» Get users
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const response = await marzban.user.getUsers();
console.log(response)
} catch (error) {
console.error(`Error listing all users:`, error.message);
}
})();π» Reset all users usage
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const response = await marzban.user.resetUsersDataUsage();
console.log(response)
} catch (error) {
console.error(`Error resetting usage for all users:`, error.message);
}
})();π» Set user owner
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const target_user = "chilluser";
const target_admin = "chilladmin";
const response = await marzban.user.setUserOwner(target_user, target_admin);
console.log(response)
} catch (error) {
console.error(`Error setting ${target_admin} as admin parent for ${target_user}:`, error.message);
}
})();π» Get expired users
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const response = await marzban.user.getExpiredUsers();
console.log(response)
} catch (error) {
console.error(`Error listing expired users:`, error.message);
}
})();π» Delete expired users
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const response = await marzban.user.deleteExpiredUsers();
console.log(response)
} catch (error) {
console.error(`Error deleting expired users:`, error.message);
}
})();π» Get user subscription
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const token = "COOLTOKENINSERTEDHERE";
const response = await marzban.user.getUserSubscription(token);
console.log(response)
} catch (error) {
console.error(`Error getting user subscription:`, error.message);
}
})();π» Get user subscription information
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const token = "COOLTOKENINSERTEDHERE";
const response = await marzban.user.getUserSubscriptionInfo(token);
console.log(response)
} catch (error) {
console.error(`Error getting user subscription information:`, error.message);
}
})();π» Get user subscription usage
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const token = "COOLTOKENINSERTEDHERE";
const response = await marzban.user.getUserSubscriptionUsage(token);
console.log(response)
} catch (error) {
console.error(`Error getting user subscription usage:`, error.message);
}
})();π» Get user subscription with client type
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const token = "COOLTOKENINSERTEDHERE";
const client = "clash";
const response = await marzban.user.getUserSubscriptionWithClientType(token, client);
console.log(response)
} catch (error) {
console.error(`Error getting user subscription with client type:`, error.message);
}
})();π» Get user templates
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const response = await marzban.templates.getUserTemplates();
console.log(response)
} catch (error) {
console.error(`Error listing user templates:`, error.message);
}
})();π» Add user template
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const template_data = {
"name": "cool_template",
"inbounds": {
"vmess": [
"VMESS_INBOUND"
],
"vless": [
"VLESS_INBOUND"
]
},
"data_limit": 0,
"expire_duration": 0
}
const response = await marzban.templates.addUserTemplate(template_data);
console.log(response)
} catch (error) {
console.error(`Error creating template:`, error.message);
}
})();π» Get user template by id
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const template_id = "1";
const response = await marzban.templates.getUserTemplateById(template_id);
console.log(response)
} catch (error) {
console.error(`Error getting template by id:`, error.message);
}
})();π» Modify user template
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const target_template_id = "1";
const template_data = {
"name": "cool_template_2",
"inbounds": {
"vmess": [
"VMESS_INBOUND"
]
},
"data_limit": 0,
"expire_duration": 0
}
const response = await marzban.templates.modifyUserTemplate(target_template_id, template_data);
console.log(response)
} catch (error) {
console.error(`Error modifying template:`, error.message);
}
})();π» Deleting user template
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const target_template_id = "1";
const response = await marzban.templates.removeUserTemplate(target_template_id);
console.log(response)
} catch (error) {
console.error(`Error deleting template:`, error.message);
}
})();π» Get node settings
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const node_settings = await marzban.node.getNodeSettings();
console.log(node_settings)
} catch (error) {
console.error(`Error getting node settings:`, error.message);
}
})();π» Add node
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const node_data = {
"name": "Germany node",
"address": "192.168.1.1",
"port": 62050,
"api_port": 62051,
"add_as_new_host": false,
"usage_coefficient": 1
}
const node = await marzban.node.addNode(nodeData);
console.log(node);
} catch (error) {
console.error(`Error while adding a new node:`, error.message);
}
})();π» Get node
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const target_node_id = "1";
const node = await marzban.node.getNode(target_node_id);
console.log(node);
} catch (error) {
console.error(`Error while getting a node:`, error.message);
}
})();π» Modify node
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const target_node_id = "1";
const new_node_data = {
"name": "Germany Node Modified",
"address": "192.168.1.1",
"port": 62050,
"api_port": 62051,
"status": "disabled",
"usage_coefficient": 1
}
const node = await marzban.node.modifyNode(target_node_id, new_node_data);
console.log(node);
} catch (error) {
console.error(`Error while modifying a node:`, error.message);
}
})();π» Remove node
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const target_node_id = "1";
const node = await marzban.node.removeNode(target_node_id);
console.log(node);
} catch (error) {
console.error(`Error while removing a node:`, error.message);
}
})();π» Get nodes
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const nodes = await marzban.node.getNodes();
console.log(nodes);
} catch (error) {
console.error(`Error while retrieving nodes:`, error.message);
}
})();π» Reconnect node
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const target_node_id = "1";
const node = await marzban.node.reconnectNode(target_node_id);
console.log(node);
} catch (error) {
console.error(`Error while retrieving nodes:`, error.message);
}
})();π» Get nodes usage
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const nodes_usage = await marzban.node.getNodesUsage();
console.log(nodes_usage);
} catch (error) {
console.error(`Error while retrieving nodes usages:`, error.message);
}
})();π» Get system stats
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const system_stats = await marzban.system.getSystemStats();
console.log(system_stats);
} catch (error) {
console.error(`Error while getting system stats:`, error.message);
}
})();π» Get inbounds
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const inbounds = await marzban.system.getInbounds();
console.log(inbounds);
} catch (error) {
console.error(`Error while getting inbounds:`, error.message);
}
})();π» Get hosts
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const hosts = await marzban.system.getHosts();
console.log(hosts);
} catch (error) {
console.error(`Error while getting hosts:`, error.message);
}
})();π» Modify hosts
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const host_data = {
"VLESS_CDN_INBOUND": [
{
"remark": "Germany Node",
"address": "192.168.1.1",
"port": 8585,
"sni": "",
"host": "",
"path": "",
"security": "inbound_default",
"alpn": "",
"fingerprint": "",
"allowinsecure": true,
"is_disabled": true,
"mux_enable": true,
"fragment_setting": "",
"noise_setting": "",
"random_user_agent": true
}
]
};
const hosts = marzban.system.modifyHosts(host_data);
console.log(hosts);
} catch (error) {
console.error(`Error while modifying hosts:`, error.message);
}
})();π» Get core stats
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const core_stats = marzban.core.getCoreStats();
console.log(core_stats);
} catch (error) {
console.error(`Error while getting core stats:`, error.message);
}
})();π» Restart core
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const restart_core = marzban.core.restartCore();
console.log(restart_core);
} catch (error) {
console.error(`Error while restarting core:`, error.message);
}
})();π» Get core config
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const core_config = marzban.core.getCoreConfig();
console.log(core_config);
} catch (error) {
console.error(`Error while getting core config:`, error.message);
}
})();π» Modify core config
const fs = require('fs');
const MarzbanAPI = require('@maniwrld/marzjs');
const marzban = MarzbanAPI({
domain: 'example.com',
port: 8080,
ssl: true,
username: 'admin',
password: 'securepassword'
});
(async () => {
try {
const xrayConfigPath = './xray_config.json';
if (!fs.existsSync(xrayConfigPath)) {
throw new Error('xray_config.json file not found');
}
const xrayConfigContent = fs.readFileSync(xrayConfigPath, 'utf8');
const xrayConfig = JSON.parse(xrayConfigContent);
const coreConfig = await marzban.core.modifyCoreConfig(xrayConfig);
console.log('Core configuration updated successfully:', coreConfig);
} catch (error) {
console.error(`Error while modifying core config:`, error.message);
}
})();π‘ Error Handling
The library provides comprehensive error handling:
- Automatic token refresh
- Detailed error messages
- Joi input validation
πΊοΈ Roadmap & Community Forks
π Future Development Roadmap
- Add TypeScript type definitions
- Implement comprehensive unit and integration tests
- Enhance WebSocket logging with more filtering options
- Create detailed documentation with more comprehensive examples
- Add support for more advanced authentication methods
- Implement rate limiting and advanced retry strategies
- Develop a CLI tool for MarzJS
π Supporting Marzban Forks
MarzJS aims to maintain compatibility with various Marzban forks to provide a versatile API client:
1. Marzneshin
- Repository: https://github.com/marzneshin/marzneshin
- Status: Active development
- Compatibility: Ongoing testing and support planned
- Key Features: Enhanced UI, additional management tools
2. MarzGosha
- Repository: https://github.com/GFWFuckers/MarzGosha
- Status: Community-driven fork
- Compatibility: Preliminary support
- Unique Characteristics: Community modifications and extensions
Note: Compatibility with these forks is an active area of development. Community feedback and contributions are welcome!
π Requirements
- Node.js 12.0.0 or higher
- Dependencies: axios, ws, qs, joi
π€ Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
π License
This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0)
π·οΈ Versioning
Current Version: 1.0.9
We use SemVer for versioning.
π Support
Encountering issues? Open an issue on GitHub.
β Support the Project
If you find MarzJS useful, please give it a star on GitHub! It helps us stay motivated and grow the project.