1. Create the Node_modules file under the node. JS Service, NPM install thrift Download Thrift to the file.
2. Write the IDL file. User.thrift content is as follows:
struct user{
1:string uid,
2:string uname,
3:bool Usex,
4:i16 Uage,
}
Service userservice{
void Add (1:user u),
User get (1:string uid),
}
3. Generate code: Run: Thrift --gen Js:node User.thrift will generate a Gen-nodejs folder in the current directory, which is the JS code we need to copy the JS code into our project. 4. Create a node. JS service segment and Client service side: var thrift = require (' thrift '); var UserService = require ('./gen-nodejs/ Userservice.js '), ttypes = require ('./gen-nodejs/user_types '); var users = {}; var server = Thrift.createserver (UserService, { add:function (user, callback) { Console.log ("Server Stored: ", User.uname); Users[user.uid] = user; callback (); }}); server.listen ( 7911); Console.log (' Server start '); client: var thrift = require (' thrift '); var userstorage = require ('./ Gen-nodejs/userstorage.js '), ttypes = require ('./gen-nodejs/user_types '); var connection = Thrift.createconnection (' localhost ', 9090), client = thrift.createclient (userstorage, connection); var user = new ttypes. UserProfile ({uid:1, &NBsp name: "Mark Slee",  BLURB: "I'll find something to put."}); connection.on (' Error ', function (err) { console.error (err);}); client.store (user, function (err, response) { if (err) { Console.error (err); } else { Console.log ("Client stored:", User.uid); Client.retrieve (user.uid, function (err, responseuser) {& nbsp if (err) { Console.error (err); } else { & nbsp Console.log ("Client retrieved:", Responseuser.uid); connection.end (); }& nbsp ); }); can now be tested.
Thrift-based node. JS RPC Service