Libraries and SDKsNode.jsInstallation and Setup

Installation and Setup

This guide will help you install and set up the CashOnRails library for your Node.js application.

Installation

Using npm

npm install cashonrails-node

Basic Setup

First, import the library into your project:

// Using ES modules
import { CashOnRailsClient } from 'cashonrails-node';
 
// Using CommonJS
const { CashOnRailsClient } = require('cashonrails-node');

Initialize the Client

Create a new instance of the CashOnRails client with your API credentials:

const client = new CashOnRailsClient('your_api_key', 'your_public_key', {
  environment: 'TEST', // Use 'LIVE' for production
});

Required Parameters

ParameterTypeDescription
apiKeystringYour CashOnRails API key from the dashboard
publicKeystringYour CashOnRails public key from the dashboard

Optional Configuration

OptionTypeDefaultDescription
environmentstring'TEST'API environment (‘TEST’ or ‘LIVE’)
timeoutnumber30000Request timeout in milliseconds
baseUrlstringundefinedCustom API base URL (if needed)

Environment Configuration

Test Environment

The test environment allows you to experiment with the API without processing real transactions:

const testClient = new CashOnRailsClient('test_api_key', 'test_public_key', {
  environment: 'TEST'
});

Live Environment

For production use with real transactions:

const liveClient = new CashOnRailsClient('live_api_key', 'live_public_key', {
  environment: 'LIVE'
});

Verifying Setup

To verify that your client is set up correctly, you can check your wallet balance:

try {
  const balance = await client.transfer.getWalletBalance('NGN');
  console.log('Connection successful! Wallet balance:', balance.data.balance);
} catch (error) {
  console.error('Setup failed:', error.message);
}

Next Steps

Now that you’ve successfully installed and configured the CashOnRails library, you can:

For complete API reference, check out the API Reference documentation.