Node.js quickstart with JavaScript
Install @siebly/hyperliquid-api and retrieve the BTC mid price with one REST request in Node.js. The example is plain JavaScript and needs no TypeScript compiler, wallet or private key.
Installation
TypeScript definitions are included.
npm install @siebly/hyperliquid-apipnpm add @siebly/hyperliquid-apiyarn add @siebly/hyperliquid-apiSee Runtime compatibility for Bun, Deno, browser and React Native setup and test results.
Make a request
Save this as prices.mjs in the project where the package is installed.
import { RestClient } from '@siebly/hyperliquid-api';
async function main() {
const client = new RestClient();
const mids = await client.getAllMids();
if (mids.BTC === undefined) {
throw new Error('BTC was not present in the mid-price response.');
}
console.log('BTC mid price:', mids.BTC);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});Run the script:
node prices.mjsExample output
getAllMids() returns a map of coin names to price strings. The script prints the BTC entry, for example:
BTC mid price: 65000.5The request uses Mainnet by default and returns prices as strings.
getAllMids reference · Error handling
For import errors, failed requests or a missing BTC price, see Troubleshooting.
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. For CommonJS, use a .cjs file with const { RestClient } = require('@siebly/hyperliquid-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.
Choose a client
| Your task | Client |
|---|---|
| Make an HTTP request and await the result | RestClient |
| Receive market data and account updates | WebsocketClient |
| Make an awaitable request over WebSocket | WebsocketAPIClient |