Facebook Pixel

Setting Up Razorpay in Node.js Account Creation, SDK Installation, and Configuration

Learn how to set up Razorpay in your Node.js application creating an account, getting API keys, installing the SDK, and configuring the Razorpay client.

Setting Up Razorpay in Node.js

This guide covers creating a Razorpay account, getting API keys, and configuring the Razorpay client in your Node.js application.

Step 1: Create a Razorpay Account

  1. Go to https://razorpay.com
  2. Click "Sign Up"
  3. Enter your email, phone, and business details
  4. Complete KYC verification (required for live mode)
  5. Once approved, you get access to the dashboard

Step 2: Get API Keys

  1. Go to Razorpay Dashboard → Settings → API Keys
  2. Generate a new key pair:
    • Key ID: rzp_test_XXXXXXXXXX (test) or rzp_live_XXXXXXXXXX (live)
    • Key Secret: xxxxxxxxxxxxxxxxxxxxxxxx
  3. Save securely the secret is shown only once

Step 3: Install the Razorpay SDK

npm install razorpay

Step 4: Configure Razorpay Client

// src/config/razorpay.js const Razorpay = require("razorpay"); const razorpay = new Razorpay({ key_id: process.env.RAZORPAY_KEY_ID, key_secret: process.env.RAZORPAY_KEY_SECRET }); module.exports = razorpay;

Step 5: Add Environment Variables

# .env RAZORPAY_KEY_ID=rzp_test_XXXXXXXXXX RAZORPAY_KEY_SECRET=xxxxxxxxxxxxxxxxxxxxxxxx RAZORPAY_WEBHOOK_SECRET=xxxxxxxxxxxxxxxxxxxxxxxx

Step 6: Test the Configuration

// Create a test order const razorpay = require("./config/razorpay"); const testOrder = async () => { try { const order = await razorpay.orders.create({ amount: 50000, // ₹500.00 (in paise) currency: "INR", receipt: "test_receipt_001" }); console.log("Test order created:", order); } catch (err) { console.error("Razorpay error:", err); } }; testOrder();

Razorpay Amount Format

Razorpay uses the smallest currency unit:

  • INR: paise (₹1 = 100 paise)
  • USD: cents ($1 = 100 cents)
// ₹500.00 amount: 50000 // 500 × 100 = 50000 paise // ₹99.99 amount: 9999 // 99.99 × 100 = 9999 paise

Test vs Live Mode

FeatureTest ModeLive Mode
Key prefixrzp_test_rzp_live_
Real moneyNoYes
Test cardsYesNo
WebhooksWorksWorks
SettlementsNoYes (T+2)

Test cards:

  • Card number: 4111 1111 1111 1111
  • Expiry: Any future date
  • CVV: Any 3 digits

The Takeaway

Setting up Razorpay involves: creating an account and completing KYC, getting API keys (key_id and key_secret) from the dashboard, installing the razorpay npm package, configuring the Razorpay client in a config file, adding keys to .env, and testing with a small order creation. Remember that amounts are in paise (₹1 = 100 paise). Use test mode for development and live mode for production.

Create a Razorpay account, get API keys from the dashboard (key_id and key_secret), install the razorpay npm package, configure the client with new Razorpay({ key_id, key_secret }), add keys to .env, and test by creating a small order.

Go to Razorpay Dashboard → Settings → API Keys → Generate Key. You get a key_id (rzp_test_... for test, rzp_live_... for live) and a key_secret. Save the secret securely it's shown only once.

Amounts are in the smallest currency unit. For INR, it's paise (₹1 = 100 paise). So ₹500.00 is amount: 50000, and ₹99.99 is amount: 9999. For USD, it's cents ($1 = 100 cents).

Card number 4111 1111 1111 1111 (Visa), any future expiry date, any 3-digit CVV. This works in test mode only. In live mode, real cards are required. No real money is charged in test mode.

Test mode uses rzp_test_ keys, no real money, test cards, no settlements. Live mode uses rzp_live_ keys, real money, real cards, settlements to your bank account (T+2 days). Switch to live mode only after full testing in test mode and KYC completion.

Ready to master Node.js completely?

Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.

Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.