blob: 8c25380d1a010da0c0fa0765de2663a3b4f44086 [file] [log] [blame] [view]
henrique5b789582014-03-15 23:11:34 +01001Thrift Node.js Library
2=========================
T Jake Luciani0c124bb2011-01-08 03:49:16 +00003
henrique5b789582014-03-15 23:11:34 +01004License
5-------
6Licensed to the Apache Software Foundation (ASF) under one
7or more contributor license agreements. See the NOTICE file
8distributed with this work for additional information
9regarding copyright ownership. The ASF licenses this file
10to you under the Apache License, Version 2.0 (the
11"License"); you may not use this file except in compliance
12with the License. You may obtain a copy of the License at
T Jake Luciani0c124bb2011-01-08 03:49:16 +000013
henrique5b789582014-03-15 23:11:34 +010014 http://www.apache.org/licenses/LICENSE-2.0
15
16Unless required by applicable law or agreed to in writing,
17software distributed under the License is distributed on an
18"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19KIND, either express or implied. See the License for the
20specific language governing permissions and limitations
21under the License.
22
James E. King, III699b5bc2017-09-14 08:07:08 -070023## Compatibility
24
25node version 4 or later is required
T Jake Luciani0c124bb2011-01-08 03:49:16 +000026
27## Install
28
29 npm install thrift
30
31## Thrift Compiler
32
raa2e4e562014-03-29 01:14:48 -070033You can compile IDL sources for Node.js with the following command:
T Jake Luciani0c124bb2011-01-08 03:49:16 +000034
35 thrift --gen js:node thrift_file
36
37## Cassandra Client Example:
38
39Here is a Cassandra example:
40
41 var thrift = require('thrift'),
42 Cassandra = require('./gen-nodejs/Cassandra')
43 ttypes = require('./gen-nodejs/cassandra_types');
44
45 var connection = thrift.createConnection("localhost", 9160),
46 client = thrift.createClient(Cassandra, connection);
47
48 connection.on('error', function(err) {
49 console.error(err);
50 });
51
52 client.get_slice("Keyspace", "key", new ttypes.ColumnParent({column_family: "ExampleCF"}), new ttypes.SlicePredicate({slice_range: new ttypes.SliceRange({start: '', finish: ''})}), ttypes.ConsistencyLevel.ONE, function(err, data) {
53 if (err) {
54 // handle err
55 } else {
56 // data == [ttypes.ColumnOrSuperColumn, ...]
57 }
58 connection.end();
59 });
60
Henrique Mendoncad407b2d2012-10-22 21:06:14 +000061<a name="int64"></a>
62## Int64
63
Jens Geyerfa133622016-12-26 11:27:24 +010064Since JavaScript represents all numbers as doubles, int64 values cannot be accurately represented naturally. To solve this, int64 values in responses will be wrapped with Thrift.Int64 objects. The Int64 implementation used is [broofa/node-int64](https://github.com/broofa/node-int64).
Henrique Mendoncad407b2d2012-10-22 21:06:14 +000065
Randy Abernethya7270072015-02-04 13:18:53 -080066## Client and server examples
Henrique Mendoncad407b2d2012-10-22 21:06:14 +000067
Randy Abernethya7270072015-02-04 13:18:53 -080068Several example clients and servers are included in the thrift/lib/nodejs/examples folder and the cross language tutorial thrift/tutorial/nodejs folder.