Node.js quickstart with JavaScript
Install binance and read the BTCUSDT Spot price with one REST request from MainClient in Node.js. The example is plain JavaScript and needs no TypeScript compiler or API credentials.
Installation
TypeScript definitions are included.
npm install binancepnpm add binanceyarn add binanceSee Runtime compatibility for Bun, Deno, browser and React Native setup and test results.
Make a request
Save this example as prices.mjs in your project.
import { MainClient } from 'binance';
async function main() {
const client = new MainClient();
const result = await client.getSymbolPriceTicker({ symbol: 'BTCUSDT' });
if (Array.isArray(result)) throw new Error('Expected a single-symbol ticker.');
console.log('BTCUSDT last price:', result.price);
}
main().catch((error) => {
console.error(error instanceof Error ? error.message : 'Request failed. See the troubleshooting guide.');
process.exitCode = 1;
});Run it with:
node prices.mjsExample output
BTCUSDT last price: 65000.00getSymbolPriceTicker() returns one ticker or an array. The example handles both shapes and prints the price string.
Choose your setup
Start with the tools you already use. Each guide includes a complete project, setup commands, expected output and cleanup where applicable.
- Node.js / JavaScript: run plain JavaScript with
importorrequire, without a TypeScript compiler. - Node.js / TypeScript: type-check and compile a Node.js price and subscription script.
- React: display live prices in a React component with effect cleanup, using Vite.
- Vite (plain JavaScript): display prices in a browser page without React.
- Next.js: return a price from a Node.js server Route Handler.
- React Native / Expo: display prices and stop subscriptions on iOS and Android.
- Bun and Deno: run a price and WebSocket script in your chosen runtime.
Each guide includes a downloadable starter generated from the maintained examples and runtime configuration. Runtime compatibility records tested versions and scope.
Module formats
The .mjs extension tells Node.js to use ES modules and import. In a CommonJS .cjs file, use const { MainClient } = require('binance') and keep the async main() function. The complete Node.js project includes both formats. TypeScript projects can use the same imports and the included type definitions; the Node.js TypeScript guide adds a compiler configuration and build commands.
Next steps
Read Market data, select a client, or subscribe to WebSocket updates. If the request fails, start with Troubleshooting.