Skip to content

Node.js quickstart with JavaScript ​

Install bybit-api and read the BTCUSDT Spot price with one REST request from RestClientV5 in Node.js. The example is plain JavaScript and needs no TypeScript compiler or API credentials.

Installation ​

TypeScript definitions are included.

sh
npm install bybit-api
sh
pnpm add bybit-api
sh
yarn add bybit-api

See 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.

js
import { RestClientV5 } from 'bybit-api';

async function main() {
  const client = new RestClientV5();
  const response = await client.getTickers({ category: 'spot', symbol: 'BTCUSDT' });
  if (response.retCode !== 0) {
    throw new Error(`Bybit ${response.retCode}: ${response.retMsg}`);
  }
  const ticker = response.result.list[0];
  if (!ticker) throw new Error('BTCUSDT was not present in the ticker response.');
  console.log('BTCUSDT last price:', ticker.lastPrice);
}
main().catch((error) => {
  console.error(error instanceof Error ? error.message : 'Request failed. See the troubleshooting guide.');
  process.exitCode = 1;
});

Run it with:

sh
node prices.mjs

Example output ​

text
BTCUSDT last price: 65000.00

getTickers() returns tickers in result.list. The example checks retCode === 0 before reading the first price.

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 import or require, 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 { RestClientV5 } = require('bybit-api') 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.

getTickers reference

Built by Siebly. Open source SDKs for exchange APIs.