File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 33 path : examples/basic.js
44 header : |-
55 NodeJS client library [repo](https://github.com/questdb/nodejs-questdb-client).
6+ - name : ilp-auth
7+ lang : javascript
8+ path : examples/auth.js
9+ header : |-
10+ NodeJS client library [repo](https://github.com/questdb/nodejs-questdb-client).
11+ auth :
12+ kid : testapp
13+ d : 9b9x5WhJywDEuo1KGQWSPNxtX-6X6R2BRCKhYMMY6n8
14+ x : aultdA0PjhD_cWViqKKyL5chm6H1n-BiZBo_48T-uqc
15+ y : __ptaol41JWSpTTL525yVEfzmY8A6Vi_QrW1FjKcHMg
16+ addr :
17+ host : localhost
18+ port : 9009
619- name : ilp-auth-tls
720 lang : javascript
821 path : examples/auth_tls.js
Original file line number Diff line number Diff line change 1+ const { Sender } = require ( "@questdb/nodejs-client" ) ;
2+
3+ async function run ( ) {
4+ // construct a JsonWebKey
5+ const CLIENT_ID = "testapp" ;
6+ const PRIVATE_KEY = "9b9x5WhJywDEuo1KGQWSPNxtX-6X6R2BRCKhYMMY6n8" ;
7+ const PUBLIC_KEY = {
8+ x : "aultdA0PjhD_cWViqKKyL5chm6H1n-BiZBo_48T-uqc" ,
9+ y : "__ptaol41JWSpTTL525yVEfzmY8A6Vi_QrW1FjKcHMg"
10+ } ;
11+ const JWK = {
12+ ...PUBLIC_KEY ,
13+ d : PRIVATE_KEY ,
14+ kid : CLIENT_ID ,
15+ kty : "EC" ,
16+ crv : "P-256" ,
17+ } ;
18+
19+ // pass the JsonWebKey to the sender
20+ // will use it for authentication
21+ const sender = new Sender ( { bufferSize : 4096 , jwk : JWK } ) ;
22+
23+ // connect() takes an optional second argument
24+ // if 'true' passed the connection is secured with TLS encryption
25+ await sender . connect ( { port : 9009 , host : "127.0.0.1" } , false ) ;
26+
27+ // send the data over the authenticated connection
28+ sender . table ( "prices" ) . symbol ( "instrument" , "EURUSD" )
29+ . floatColumn ( "bid" , 1.0197 ) . floatColumn ( "ask" , 1.0224 ) . atNow ( ) ;
30+ await sender . flush ( ) ;
31+
32+ // close the connection after all rows ingested
33+ await sender . close ( ) ;
34+ return 0 ;
35+ }
36+
37+ run ( ) . then ( value => console . log ( value ) ) . catch ( err => console . log ( err ) ) ;
You can’t perform that action at this time.
0 commit comments