@@ -9,41 +9,45 @@ The client requires Node.js v16 or newer version.
99npm i -s @questdb/nodejs-client
1010```
1111
12+ ## Configuration options
13+
14+ Detailed description of the client's configuration options can be found in
15+ the <a href =" SenderOptions.html " >SenderOptions</a > documentation.
16+
1217## Examples
1318
19+ The examples below demonstrate how to use the client. <br >
20+ For more details, please, check the <a href =" Sender.html " >Sender</a >'s documentation.
21+
1422### Basic API usage
1523
1624``` javascript
1725const { Sender } = require (' @questdb/nodejs-client' );
1826
1927async function run () {
20- const sender = new Sender ();
21-
22- // connect to QuestDB
23- // host and port are required in connect options
24- await sender .connect ({port: 9009 , host: ' localhost' });
28+ // create a sender using HTTP protocol
29+ const sender = Sender .fromConfig (' http::addr=localhost:9000' );
2530
2631 // add rows to the buffer of the sender
27- sender .table (' prices' ).symbol (' instrument' , ' EURUSD' )
32+ await sender .table (' prices' ).symbol (' instrument' , ' EURUSD' )
2833 .floatColumn (' bid' , 1.0195 ).floatColumn (' ask' , 1.0221 )
2934 .at (Date .now (), ' ms' );
30- sender .table (' prices' ).symbol (' instrument' , ' GBPUSD' )
35+ await sender .table (' prices' ).symbol (' instrument' , ' GBPUSD' )
3136 .floatColumn (' bid' , 1.2076 ).floatColumn (' ask' , 1.2082 )
3237 .at (Date .now (), ' ms' );
3338
3439 // flush the buffer of the sender, sending the data to QuestDB
35- // the buffer is cleared after the data is sent and the sender is ready to accept new data
40+ // the buffer is cleared after the data is sent, and the sender is ready to accept new data
3641 await sender .flush ();
3742
38- // add rows to the buffer again and send it to the server
39- sender .table (' prices' ).symbol (' instrument' , ' EURUSD' )
43+ // add rows to the buffer again, and send it to the server
44+ await sender .table (' prices' ).symbol (' instrument' , ' EURUSD' )
4045 .floatColumn (' bid' , 1.0197 ).floatColumn (' ask' , 1.0224 )
4146 .at (Date .now (), ' ms' );
4247 await sender .flush ();
4348
4449 // close the connection after all rows ingested
4550 await sender .close ();
46- return new Promise (resolve => resolve (0 ));
4751}
4852
4953run ()
@@ -57,23 +61,11 @@ run()
5761const { Sender } = require (' @questdb/nodejs-client' );
5862
5963async function run () {
60- // authentication details
61- const CLIENT_ID = ' testapp' ;
62- const PRIVATE_KEY = ' 9b9x5WhJywDEuo1KGQWSPNxtX-6X6R2BRCKhYMMY6n8' ;
63- const AUTH = {
64- keyId: CLIENT_ID ,
65- token: PRIVATE_KEY
66- };
67-
68- // pass the authentication details to the sender
69- const sender = new Sender ({auth: AUTH });
70-
71- // connect() takes an optional second argument
72- // if 'true' passed the connection is secured with TLS encryption
73- await sender .connect ({port: 9009 , host: ' localhost' }, true );
64+ // create a sender using HTTPS protocol with username and password authentication
65+ const sender = Sender .fromConfig (' https::addr=localhost:9000;username=user1;password=pwd' );
7466
7567 // send the data over the authenticated and secure connection
76- sender .table (' prices' ).symbol (' instrument' , ' EURUSD' )
68+ await sender .table (' prices' ).symbol (' instrument' , ' EURUSD' )
7769 .floatColumn (' bid' , 1.0197 ).floatColumn (' ask' , 1.0224 )
7870 .at (Date .now (), ' ms' );
7971 await sender .flush ();
@@ -91,20 +83,8 @@ run().catch(console.error);
9183import { Sender } from ' @questdb/nodejs-client' ;
9284
9385async function run(): Promise <number > {
94- // authentication details
95- const CLIENT_ID: string = ' testapp' ;
96- const PRIVATE_KEY: string = ' 9b9x5WhJywDEuo1KGQWSPNxtX-6X6R2BRCKhYMMY6n8' ;
97- const AUTH: { keyId: string , token: string } = {
98- keyId: CLIENT_ID ,
99- token: PRIVATE_KEY
100- };
101-
102- // pass the authentication details to the sender
103- const sender: Sender = new Sender ({auth: AUTH });
104-
105- // connect() takes an optional second argument
106- // if 'true' passed the connection is secured with TLS encryption
107- await sender .connect ({port: 9009 , host: ' localhost' }, true );
86+ // create a sender using HTTPS protocol with bearer token authentication
87+ const sender: Sender = Sender .fromConfig (' https::addr=localhost:9000;token=Xyvd3er6GF87ysaHk' );
10888
10989 // send the data over the authenticated and secure connection
11090 sender .table (' prices' ).symbol (' instrument' , ' EURUSD' )
@@ -160,14 +140,13 @@ async function run() {
160140 } else {
161141 // it is important that each worker has a dedicated sender object
162142 // threads cannot share the sender because they would write into the same buffer
163- const sender = new Sender ();
164- await sender .connect ({ port: 9009 , host: ' localhost' });
143+ const sender = Sender .fromConfig (' http::addr=localhost:9000' );
165144
166145 // subscribe for the market data of the ticker assigned to the worker
167146 // ingest each price update into the database using the sender
168147 let count = 0 ;
169148 await subscribe (workerData .ticker , async (tick ) => {
170- sender
149+ await sender
171150 .table (' prices' )
172151 .symbol (' ticker' , tick .ticker )
173152 .floatColumn (' price' , tick .price )
0 commit comments