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

kite-auto-login

v1.0.0

Published

Zero-dependency automated login for Zerodha Kite Connect. Handles credentials, TOTP, and session exchange — returns an access_token.

Readme

kite-auto-login

Zero-dependency automated login for Zerodha Kite Connect. Handles credentials, TOTP 2FA, and session exchange — returns an access_token.

Kite tokens expire daily at 6:00 AM IST. This package automates the full re-authentication flow so you don't have to manually log in through the browser every trading day.

Install

npm install kite-auto-login

Requires Node.js 18+ (uses built-in fetch and crypto).

Usage

import { kiteLogin } from "kite-auto-login";

const session = await kiteLogin({
  apiKey: "your_kite_api_key",
  apiSecret: "your_kite_api_secret",
  userId: "AB1234",
  password: "your_zerodha_password",
  totpSecret: "YOUR_BASE32_TOTP_SECRET",
});

console.log(session.accessToken); // Use with KiteConnect SDK or raw API calls
console.log(session.expiresAt);   // Next 6:00 AM IST

With the KiteConnect SDK

import { KiteConnect } from "kiteconnect";
import { kiteLogin } from "kite-auto-login";

const session = await kiteLogin({ /* credentials */ });

const kc = new KiteConnect({ api_key: "your_api_key" });
kc.setAccessToken(session.accessToken);

const holdings = await kc.getHoldings();

Daily cron (e.g. with node-cron)

import cron from "node-cron";
import { kiteLogin } from "kite-auto-login";

// Run at 8:55 AM IST (3:25 UTC) every weekday
cron.schedule("25 3 * * 1-5", async () => {
  try {
    const session = await kiteLogin({ /* credentials */ });
    console.log(`Token refreshed, expires ${session.expiresAt.toISOString()}`);
    // Store session.accessToken in your DB, Redis, etc.
  } catch (err) {
    console.error("Auto-login failed:", err);
  }
});

Getting your TOTP secret

The TOTP secret is the base32 seed your authenticator app uses to generate 6-digit codes.

  1. Go to console.zerodha.comSettingsSecurity
  2. Reset your TOTP (you'll need to re-setup 2FA)
  3. When the QR code appears, click "Can't scan? Show key"
  4. Copy the base32 string (looks like MSMMH3G44BS42MI3...)
  5. Also scan the QR with your authenticator app so manual login still works

API

kiteLogin(credentials): Promise<KiteSession>

| Parameter | Type | Description | |-----------|------|-------------| | apiKey | string | Kite Connect API key | | apiSecret | string | Kite Connect API secret | | userId | string | Zerodha client ID (e.g. "AB1234") | | password | string | Zerodha password | | totpSecret | string | Base32 TOTP secret from 2FA setup |

Returns:

| Field | Type | Description | |-------|------|-------------| | accessToken | string | Access token for Kite API calls | | publicToken | string | Public token for non-sensitive operations | | userId | string | Zerodha user ID | | expiresAt | Date | Token expiry (next 6:00 AM IST) |

KiteLoginError

Thrown on failure with:

  • step: "login" | "twofa" | "redirect" | "session" — which step failed
  • details: Raw response data from Zerodha
try {
  await kiteLogin({ /* ... */ });
} catch (err) {
  if (err instanceof KiteLoginError) {
    console.error(`Failed at step: ${err.step}`, err.details);
  }
}

generateTOTP(secret): string

Exported for advanced use. Generates a 6-digit TOTP code from a base32 secret.

import { generateTOTP } from "kite-auto-login";

const code = generateTOTP("YOUR_BASE32_SECRET");

License

MIT