NSE and BSE API for Node.js and TypeScript: A Developer Guide (2026)

To use an NSE API in Node.js, install the drishti-sdk software development kit (SDK) from npm, create a DrishtiClient with the DRISHTI_API_KEY environment variable, and call typed methods such as getAnnouncements(). The same client opens a WebSocket (a persistent two-way connection) for live filings and news, so one package covers the dashboard route and the alert bot.
This guide is for builders of Next.js apps, Slack or Discord bots and dashboards that need National Stock Exchange of India (NSE) and BSE Ltd (BSE) company events. Every snippet ran against the live API with drishti-sdk 1.0.18 on Node.js 24.
Key takeaways
drishti-sdkships its own TypeScript types, so responses and stream events autocomplete.- Use REST (plain HTTP requests) for pages and backfills, WebSocket for live events and batch jobs for bulk summaries.
- The session reconnects and resubscribes for you, but missed events are not replayed, so catch up over REST.
- Keep the API key on your server. Browsers call your route, never Drishti.
- For OHLC (open, high, low, close) prices, add a price-feed vendor; for orders, a broker API.
On this page
- What you will build with an NSE API in Node.js
- Install the SDK from npm
- Make your first TypeScript stock market API call
- Serve watchlist announcements from an Express route
- Push WebSocket stock data to Slack or Discord
- Keep your API key server-side
- REST, WebSocket or batch from Node.js
- Which provider fits your Node.js build
- Frequently asked questions
- Start with one request in Sandbox
What you will build with an NSE API in Node.js
The build is two small Node.js processes sharing one key. An Express route returns the latest announcements for a fixed watchlist, so your frontend reads JSON from your own backend. A worker holds a WebSocket open and forwards each new filing or news item to a Slack or Discord webhook.
Drishti is an independent market-intelligence API built on official exchange-backed sources. It does not scrape NSE or BSE websites. Each announcement carries an AI-written summary and category, so the bot posts something readable instead of a PDF link.
Install the SDK from npm
The drishti-sdk package on npm needs Node.js 18 or newer. The worker uses the global WebSocket that Node.js 22+ provides; older runtimes can pass one through the webSocketImpl option.
npm install drishti-sdk express
npm install -D typescript tsx @types/express @types/node
export DRISHTI_API_KEY="paste-your-key-here"
The package is ECMAScript module (ESM) only, so set "type": "module" in package.json and run files with npx tsx file.ts. The TypeScript SDK reference lists every method and option.
Make your first TypeScript stock market API call
This script pulls the five latest announcements for two companies. The response is typed as a union of list and detail shapes; narrowing to AnnouncementDetail is safe because detailed: true is set.
import { DrishtiApiError, DrishtiClient } from "drishti-sdk";
import type { AnnouncementDetail } from "drishti-sdk";
const client = new DrishtiClient({ apiKey: process.env.DRISHTI_API_KEY! });
try {
const page = await client.getAnnouncements({
symbols: ["RELIANCE", "TCS"],
detailed: true,
limit: 5,
});
for (const item of page.data as AnnouncementDetail[]) {
console.log(item.date, item.symbol, item.category, item.summary);
}
console.log("more pages:", page.has_next);
} catch (error) {
if (error instanceof DrishtiApiError) {
console.error(error.statusCode, error.body);
}
throw error;
}
It printed rows like 2026-10-15T07:58:51.453000+00:00 TCS Acquisition Tata Consultancy Services Limited has completed the acquisition of BBY Services India LLP..., followed by more pages: true. Detail rows also carry long_summary and extracted_information. When has_next is true, request the next page.
The client sends the key as an X-API-Key header and retries 408, 409, 425, 429, 500, 502, 503 and 504 responses with backoff. Other failures throw DrishtiApiError with the status and body. All five Drishti SDKs pass one conformance test suite, so a port to Python or Java behaves the same.
Serve watchlist announcements from an Express route
Your frontend should never hold the key, so give it a route. This handler fetches a fixed watchlist, trims each row to what the UI needs and caches for a minute.
import express from "express";
import { DrishtiClient } from "drishti-sdk";
const client = new DrishtiClient({ apiKey: process.env.DRISHTI_API_KEY! });
const WATCHLIST = ["RELIANCE", "TCS", "INFY", "HDFCBANK"];
const CACHE_MS = 60_000;
let cache: { at: number; body: unknown[] } | null = null;
const app = express();
app.get("/api/announcements", async (_req, res) => {
if (cache && Date.now() - cache.at < CACHE_MS) {
res.json(cache.body);
return;
}
try {
const page = await client.getAnnouncements({ symbols: WATCHLIST, limit: 20 });
const body = page.data.map(({ id, symbol, date, category, summary }) => ({
id, symbol, date, category, summary,
}));
cache = { at: Date.now(), body };
res.json(body);
} catch (error) {
console.error("drishti request failed", error);
res.status(502).json({ error: "upstream_unavailable" });
}
});
app.listen(3000, () => console.log("http://localhost:3000/api/announcements"));
In our test the first request returned 20 rows in about 0.2 seconds and the cached repeat in about 2 milliseconds. Without the cache, every page view costs a request, and Sandbox allows 10 per minute.
The watchlist lives on the server on purpose. If you accept symbols from the query string, validate them so a stranger cannot spend your credits. The same body works in a Next.js route handler or a Fastify route.
Push WebSocket stock data to Slack or Discord
An alert bot should react when a filing lands, not on a polling timer. Live WebSocket stock data for Indian companies comes through client.websocket(), which connects on creation. This worker subscribes to announcements and news and posts each event to a webhook.
import { DrishtiClient } from "drishti-sdk";
const client = new DrishtiClient({ apiKey: process.env.DRISHTI_API_KEY! });
const WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL!;
const WATCHLIST = ["RELIANCE", "TCS", "INFY", "HDFCBANK"];
async function post(text: string): Promise<void> {
// Slack incoming webhooks take { text }; Discord webhooks take { content }.
const res = await fetch(WEBHOOK_URL, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text }),
});
if (!res.ok) console.error("webhook failed", res.status);
}
const ws = client.websocket({
onSubscribed: (event) => console.log("subscribed", event),
onAnnouncements: (a) => post(`*${a.symbol}* ${a.category ?? "Filing"}: ${a.summary ?? ""}`),
onNews: (n) => post(`${n.symbol ?? "Market"} news (${n.sentiment ?? "n/a"}): ${n.title ?? ""}`),
onError: (event) => console.error("stream error", event),
onReconnectAttempt: (attempt, delayMs) => console.warn("reconnecting", attempt, delayMs),
});
await ws.subscribe({ product: "announcements", symbols: WATCHLIST, detailed: false });
await ws.subscribe({ product: "news", symbols: WATCHLIST });
process.on("SIGTERM", () => void ws.close());
Handlers are typed by channel, so a.summary and n.sentiment autocomplete without casts. On our run both subscriptions were acknowledged with the normalised symbol list. See the Slack and Discord webhook docs for payload options.
The session reconnects with backoff, replays subscriptions and forces a reconnect after 90 silent seconds by default. It cannot recover events sent while offline. The WebSocket guide shows the fix: in onOpen, call getAnnouncements() and keep rows newer than your last date, deduplicated by id.
Keep your API key server-side
The SDK also ships a browser bundle on jsDelivr and unpkg. Fine for a demo, dangerous in production. The README is direct:
Any API key used in the browser is visible in page source and network requests. Use the CDN bundle only for demos, prototypes, or internal tools where users supply their own key. For production apps, install with npm on the server or proxy Drishti calls through your backend.
In Next.js, call the SDK only from route handlers, server actions or server components, and never put the key in a NEXT_PUBLIC_ variable. Run the WebSocket worker on your backend and push events to browsers yourself.
REST, WebSocket or batch from Node.js
| Access mode | Use it from Node.js when | SDK entry point | Watch out for |
|---|---|---|---|
| REST | A page, cron job or backfill needs records | getAnnouncements(), getNews(), getEarnings() | Paginate with has_next; cache to respect rate limits |
| WebSocket | A worker reacts to news, filings, earnings, concalls, block deals or alerts | client.websocket(), subscribe() | Paid plans only (Starter 100 symbols, Pro 1,000); no replay |
| Batch | You need many portfolio summaries, such as nightly digests | submitBatchJobAndWait() with a JSONL (JSON Lines) file | 50 credits per job plus 5 per summary; run it off the request path |
Which provider fits your Node.js build
Drishti is our product, so weigh that when you read this comparison. Drishti covers company events: summarised announcements, earnings, concall analysis, news with sentiment, alerts and block deals. Drishti does not provide tick-by-tick prices or submit orders. If you need to place orders, use a broker API such as Kite Connect, Upstox or DhanHQ.
| If your build needs | Consider | Why it may fit | Check before choosing |
|---|---|---|---|
| Company filings, earnings and news in a TypeScript app or bot | Drishti | Typed npm SDK with REST, a reconnecting WebSocket session and batch jobs | Sandbox is REST only; live streams need a paid plan |
| Real-time tick and historical price data from a Node.js service | TrueData | Authorised vendor for NSE, BSE and MCX (Multi Commodity Exchange); WebSocket and REST APIs; lists a JS/Node library | API pricing is not published; licence is for the subscriber's own use |
| Real-time, delayed and historical feeds with option chains | Global Datafeeds | Authorised vendor with WebSocket, REST and FIX (Financial Information eXchange); Node sample code | Pricing is on request; confirm the exact product and segments |
| A research UI with filings timelines and metrics | Tijori Finance | Investor platform with 6,000+ operational metrics, screener and alerts | Public developer APIs are limited; no self-serve docs or SDK found |
| Screeners, scores and alerts for investors | Trendlyne | Screeners, stock scores, results dashboard and Excel Connect | No self-serve public API documentation found |
| Ready-made scans for results and announcements | StockScans | Research platform with scans, watchlists and a free entry tier | No public developer API listed |
This is a product-fit comparison, not a ranking. Many stacks combine a price vendor, Drishti and a broker API.
Frequently asked questions
Is there an NSE API package on npm?
Yes, from data providers. drishti-sdk is Drishti's official npm package for NSE and BSE company events, and TrueData's site lists a JS/Node library for price data.
Is there a BSE API for JavaScript?
Yes, through providers rather than the exchange. Drishti's announcement and earnings data covers NSE and BSE listed companies, and you can filter by symbols or BSE scrip_codes from the same JavaScript client.
Can I call the Drishti API from React or the browser?
Only for demos where users supply their own key. In production, React should fetch your server route.
Does the free Sandbox include WebSockets?
No. Sandbox gives 1,000 one-time trial credits, 10 requests per minute and 1,000 REST requests per day, with no WebSocket access. Starter at ₹2,000 per month adds WebSocket streams for 100 symbols; see pricing.
Start with one request in Sandbox
Create a free Sandbox key, set DRISHTI_API_KEY and run the first-call script on your watchlist. Add the Express route next, then a paid plan when you want the Slack worker. The TypeScript SDK docs list every method, and the SDK comparison hub covers the other four languages.
Product pages, package registries and documentation checked on 21 October 2026. Prices and features change, so confirm on each provider's site before you buy. This article is not investment advice.



