Big news!Introducing Socket AI - ChatGPT-Powered Threat Analysis.Learn more


Package Overview
File Explorer

Advanced tools


Tarantool driver for 1.7+


Version published
Weekly downloads
decreased by-27.5%

Weekly downloads



Node.js driver for tarantool 1.7+

Build Status

Node tarantool driver for 1.7+ support Node.js v.4+.

Based on go-tarantool and implements Tarantool’s binary protocol, for more information you can read them or basic documentation at Tarantool manual.

Code architecture and some features in version 3 borrowed from the ioredis.

msgpack-lite package used as MsgPack encoder/decoder.

Table of contents


npm install --save tarantool-driver


new Tarantool([port], [host], [options]) ⇐ EventEmitter

Creates a Tarantool instance, extends EventEmitter.

Connection related custom events:

  • "reconnecting" - emitted when the client try to reconnect, first argument is retry delay in ms.
  • "connect" - emitted when the client connected and auth passed (if username and password provided), first argument is an object with host and port of the Taranool server.
[port]number | string | Object3301Port of the Tarantool server, or a URI string (see the examples in tarantool configuration doc), or the options object(see the third argument).
[host]string | Object"localhost"Host of the Tarantool server, when the first argument is a URL string, this argument is an object represents the options.
[options]ObjectOther options.
[options.port]number6379Port of the Tarantool server.
[]string"localhost"Host of the Tarantool server.
[options.username]stringnullIf set, client will authenticate with the value of this option when connected.
[options.password]stringnullIf set, client will authenticate with the value of this option when connected.
[options.timeout]number0The milliseconds before a timeout occurs during the initial connection to the Tarantool server.
[options.lazyConnect]booleanfalseBy default, When a new Tarantool instance is created, it will connect to Tarantool server automatically. If you want to keep disconnected util a command is called, you can pass the lazyConnect option to the constructor.
[options.reserveHosts]array[]Array of strings - reserve hosts. Client will try to connect to hosts from this array after loosing connection with current host and will do it cyclically. See example below.
[options.beforeReserve]number2Number of attempts to reconnect before connect to next host from the reserveHosts
[options.retryStrategy]functionSee below

Reserve hosts example:

let connection = new Tarantool({ host: '', port: 33013, username: 'user' password: 'secret', reserveHosts: [ '', '' ], beforeReserve: 1 }) // connect to -> dead // ↓ // trying connect to -> dead // ↓ // trying connect to -> dead // ↓ // trying connect to ...etc

Retry strategy

By default, node-tarantool-driver client will try to reconnect when the connection to Tarantool is lost except when the connection is closed manually by tarantool.disconnect().

It's very flexible to control how long to wait to reconnect after disconnection using the retryStrategy option:

var tarantool = new Tarantool({ // This is the default value of `retryStrategy` retryStrategy: function (times) { var delay = Math.min(times * 50, 2000); return delay; } });

retryStrategy is a function that will be called when the connection is lost. The argument times means this is the nth reconnection being made and the return value represents how long (in ms) to wait to reconnect. When the return value isn't a number, node-tarantool-driver will stop trying to reconnect, and the connection will be lost forever if the user doesn't call tarantool.connect() manually.

This feature is borrowed from the ioredis

Usage example

We use TarantoolConnection instance and connect before other operations. Methods call return promise( Available methods with some testing: select, update, replace, insert, delete, auth, destroy.

var TarantoolConnection = require('tarantool-driver'); var conn = new TarantoolConnection(''); // select arguments space_id, index_id, limit, offset, iterator, key, 0, 1, 0, 'eq', [50]) .then(funtion(results){ doSomeThingWithResults(results); });

Msgpack implementation

You can use any implementation that can be duck typing with next interface:

//msgpack implementation example /* @interface decode: (Buffer buf) encode: (Object obj) */ var exampleCustomMsgpack = { encode: function(obj){ return yourmsgpack.encode(obj); }, decode: function(buf){ return yourmsgpack.decode(obj); } };

By default use msgpack-lite package.

API reference

tarantool.connect() ⇒ Promise

Resolve if connected. Or reject if not.

tarantool._auth(login: String, password: String) ⇒ Promise

An internal method. The connection should be established before invoking.

Auth with using chap-sha1. About authenthication more here: authentication Number or String, indexId: Number or String, limit: Number, offset: Number, iterator: Iterator, key: tuple) ⇒ Promise

Iterators. Available iterators: 'eq', 'req', 'all', 'lt', 'le', 'ge', 'gt', 'bitsAllSet', 'bitsAnySet', 'bitsAllNotSet'.

It's just select. Promise resolve array of tuples.

Some examples:, 0, 1, 0, 'eq', [50]); //same as'test', 'primary', 1, 0, 'eq', [50]);

You can use space name or index name instead of id, but it will some requests for get this metadata. That information actual for delete, replace, insert, update too.

tarantool.selectCb(spaceId: Number or String, indexId: Number or String, limit: Number, offset: Number, iterator: Iterator, key: tuple, callback: function(success), callback: function(error))

Same as but with callbacks.

tarantool.delete(spaceId: Number or String, indexId: Number or String, key: tuple) ⇒ Promise

Promise resolve an array of deleted tuples.

tarantool.update(spaceId: Number or String, indexId: Number or String, key: tuple, ops) ⇒ Promise

Possible operators.

Promise resolve an array of updated tuples.

tarantool.insert(spaceId: Number or String, tuple) ⇒ Promise

More you can read here: Insert

Promise resolve a new tuple.

tarantool.upsert(spaceId: Number or String, ops: array of operations, tuple: tuple) ⇒ Promise

About operation: Upsert

Possible operators.

Promise resolve nothing.

tarantool.replace(spaceId: Number or String, tuple: tuple) ⇒ Promise

More you can read here: Replace

Promise resolve a new or replaced tuple. String, args...) ⇒ Promise

Call a function with arguments.

You can create function on tarantool side:

function myget(id) val ={id} return val[1] end

And then use something like this:'myget', 4) .then(function(value){ console.log(value); });

If you have a 2 arguments function just send a second arguments in this way:'my2argumentsfunc', 'first', 'second argument')

And etc like this.

Because lua support a multiple return it's always return array or undefined.

tarantool.eval(expression: String) ⇒ Promise

Evaluate and execute the expression in Lua-string. Eval

Promise resolve result:any.


conn.eval('return box.session.user()') .then(function(res){ console.log('current user is:' res[0]) })

tarantool.sql(query: String, bindParams: Array) -> Promise

It's accessible only in 2.1 tarantool.

You can use SQL query that is like sqlite dialect to query a tarantool database.

You can insert or select or create database.

More about it here.


await connection.insert('tags', ['tag_1', 1]) await connection.insert('tags', ['tag_2', 50]) connection.sql('select * from "tags"') .then((res) => { console.log('Successful get tags', res); }) .catch((error) => { console.log(error); });

P.S. If you using lowercase in your space name you need to use a double quote for their name.

It doesn't work for space without format. ⇒ Promise

Promise resolve true.

tarantool.destroy(interupt: Boolean) ⇒ Promise



Disconnect from Tarantool.

This method closes the connection immediately, and may lose some pending replies that haven't written to client.


Set environment variable "DEBUG" to "tarantool-driver:*"


It's ok you can do whatever you need. I add log options for some technical information it can be help for you. If i don't answer i just miss email :( it's a lot emails from github so please write me to directly if i don't answer in one day.



Remove let for support old nodejs version


Add support SQL


Fix eval and call


Increase request id limit to SMI Maximum


Fix parser thx @tommiv


New version with reconnect in alpha.


Fix test for call changes and remove unuse upsert parameter (critical change API for upsert)


Add clear schema cache on change schema id


Change msgpack5 to msgpack-lite(thx to @arusakov). Add msgpack as option for connection. Bump msgpack5 for work at new version.


Add upsert operation. Key is now can be just a number.


finish multihost feature



Last updated on 27 Apr 2019

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket SOC 2 Logo


  • Package Issues
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc