@@ -9,18 +9,20 @@ The client requires Node.js v20 or newer version.
99``` shell
1010# With npm
1111npm i -s @questdb/nodejs-client
12+
1213# With yarn
1314yarn add @questdb/nodejs-client
15+
1416# With pnpm
1517pnpm add @questdb/nodejs-client
1618```
1719
1820## Compatibility table
1921
20- | QuestDB version | Node.js client version | HTTP Agent |
21- | --------------- | ---------------------- | ------------ |
22- | ^4.0.0 | >=v20.X.X | Undici Agent |
23- | ^3.0.0 | <v20.X.X | Http. Agent |
22+ | QuestDB client version | Node.js version | HTTP Agent |
23+ | ------------------------| --------------- | -------------- |
24+ | ^4.0.0 | >=v20.X.X | Undici Agent |
25+ | ^3.0.0 | <v20.X.X | Http Agent |
2426
2527## Configuration options
2628
@@ -38,39 +40,68 @@ For more details, please, check the <a href="https://questdb.github.io/nodejs-qu
3840import { Sender } from " @questdb/nodejs-client" ;
3941
4042async function run () {
41- // create a sender using HTTP protocol
42- const sender = Sender .fromConfig (" http::addr=127.0.0.1:9000" );
43-
44- // add rows to the buffer of the sender
45- await sender
46- .table (" trades" )
47- .symbol (" symbol" , " ETH-USD" )
48- .symbol (" side" , " sell" )
49- .floatColumn (" price" , 2615.54 )
50- .floatColumn (" amount" , 0.00044 )
51- .at (Date .now (), " ms" );
52-
53- // flush the buffer of the sender, sending the data to QuestDB
54- // the buffer is cleared after the data is sent, and the sender is ready to accept new data
55- await sender .flush ();
56-
57- // close the connection after all rows ingested
58- // unflushed data will be lost
59- await sender .close ();
43+ // create a sender
44+ const sender = await Sender .fromConfig (' http::addr=localhost:9000' );
45+
46+ // order book snapshots
47+ const orderBooks = [
48+ {
49+ symbol: ' BTC-USD' ,
50+ exchange: ' COINBASE' ,
51+ timestamp: Date .now (),
52+ bidPrices: [50100.25 , 50100.20 , 50100.15 , 50100.10 , 50100.05 ],
53+ bidSizes: [0.5 , 1.2 , 2.1 , 0.8 , 3.5 ],
54+ askPrices: [50100.30 , 50100.35 , 50100.40 , 50100.45 , 50100.50 ],
55+ askSizes: [0.6 , 1.5 , 1.8 , 2.2 , 4.0 ]
56+ },
57+ {
58+ symbol: ' ETH-USD' ,
59+ exchange: ' COINBASE' ,
60+ timestamp: Date .now (),
61+ bidPrices: [2850.50 , 2850.45 , 2850.40 , 2850.35 , 2850.30 ],
62+ bidSizes: [5.0 , 8.2 , 12.5 , 6.8 , 15.0 ],
63+ askPrices: [2850.55 , 2850.60 , 2850.65 , 2850.70 , 2850.75 ],
64+ askSizes: [4.5 , 7.8 , 10.2 , 8.5 , 20.0 ]
65+ }
66+ ];
67+
68+ try {
69+ // add rows to the buffer of the sender
70+ for (const orderBook of orderBooks) {
71+ await sender
72+ .table (' order_book_l2' )
73+ .symbol (' symbol' , orderBook .symbol )
74+ .symbol (' exchange' , orderBook .exchange )
75+ .arrayColumn (' bid_prices' , orderBook .bidPrices )
76+ .arrayColumn (' bid_sizes' , orderBook .bidSizes )
77+ .arrayColumn (' ask_prices' , orderBook .askPrices )
78+ .arrayColumn (' ask_sizes' , orderBook .askSizes )
79+ .at (orderBook .timestamp , ' ms' );
80+ }
81+
82+ // flush the buffer of the sender, sending the data to QuestDB
83+ // the buffer is cleared after the data is sent, and the sender is ready to accept new data
84+ await sender .flush ();
85+ } finally {
86+ // close the connection after all rows ingested
87+ await sender .close ();
88+ }
6089}
6190
6291run ().then (console .log ).catch (console .error );
6392```
6493
6594### Authentication and secure connection
6695
96+ #### Username and password authentication
97+
6798``` javascript
6899import { Sender } from " @questdb/nodejs-client" ;
69100
70101async function run () {
71102 // create a sender using HTTPS protocol with username and password authentication
72103 const sender = Sender .fromConfig (
73- " https::addr=127.0.0.1:9000;username=admin;password=quest; " ,
104+ " https::addr=127.0.0.1:9000;username=admin;password=quest" ,
74105 );
75106
76107 // send the data over the authenticated and secure connection
@@ -90,15 +121,15 @@ async function run() {
90121run ().catch (console .error );
91122```
92123
93- ### TypeScript example
124+ #### Token authentication
94125
95126``` typescript
96127import { Sender } from " @questdb/nodejs-client" ;
97128
98129async function run(): Promise <void > {
99130 // create a sender using HTTPS protocol with bearer token authentication
100131 const sender: Sender = Sender .fromConfig (
101- " https::addr=127.0.0.1:9000;token=Xyvd3er6GF87ysaHk; " ,
132+ " https::addr=127.0.0.1:9000;token=Xyvd3er6GF87ysaHk" ,
102133 );
103134
104135 // send the data over the authenticated and secure connection
0 commit comments