@@ -9,18 +9,20 @@ The client requires Node.js v20 or newer version.
9
9
``` shell
10
10
# With npm
11
11
npm i -s @questdb/nodejs-client
12
+
12
13
# With yarn
13
14
yarn add @questdb/nodejs-client
15
+
14
16
# With pnpm
15
17
pnpm add @questdb/nodejs-client
16
18
```
17
19
18
20
## Compatibility table
19
21
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 |
24
26
25
27
## Configuration options
26
28
@@ -38,39 +40,68 @@ For more details, please, check the <a href="https://questdb.github.io/nodejs-qu
38
40
import { Sender } from " @questdb/nodejs-client" ;
39
41
40
42
async 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
+ }
60
89
}
61
90
62
91
run ().then (console .log ).catch (console .error );
63
92
```
64
93
65
94
### Authentication and secure connection
66
95
96
+ #### Username and password authentication
97
+
67
98
``` javascript
68
99
import { Sender } from " @questdb/nodejs-client" ;
69
100
70
101
async function run () {
71
102
// create a sender using HTTPS protocol with username and password authentication
72
103
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" ,
74
105
);
75
106
76
107
// send the data over the authenticated and secure connection
@@ -90,15 +121,15 @@ async function run() {
90
121
run ().catch (console .error );
91
122
```
92
123
93
- ### TypeScript example
124
+ #### Token authentication
94
125
95
126
``` typescript
96
127
import { Sender } from " @questdb/nodejs-client" ;
97
128
98
129
async function run(): Promise <void > {
99
130
// create a sender using HTTPS protocol with bearer token authentication
100
131
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" ,
102
133
);
103
134
104
135
// send the data over the authenticated and secure connection
0 commit comments