Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



    A C++ "flexible variable" library, designed for conveniently dealing with JSON/BSON-like data within C++.

    It was designed to make writing the bridge code for C++ Node modules easier -- but also happens to be fairly useful as a C++ library on its own. It allows code such as follows to be written in C++.

    // Store basic C++ types 
    flexvar v, q;
    q = 42.001f;
    v["x"] = 4;
    v["y"] = 12;
    v["message"] = "Hello World";
    // Implicit conversion to read as C++ types
    float x = v["x"];
    int   y = v["y"];
    // Iteration for indexed and associative arrays 
    v.each([](flexvar key, flexvar value) {
        std::cout << key.toString() << " : " value.toString() << std::endl;

    This in turn is very easy to recursively copy into a Google V8 Object for transfer of data into Javascript code.


    npm install --dev
    node demo

    The script demo.js invokes the package build script and runs the first example executable. The source is located in the examples directory.

    Building the Library

    Be sure to run npm install --dev first and to install CMake then run:

    node rebuild

    This will invoke CMake to configure and do the build. The resulting library will be named, depending on the platform, as:

    build/pusher.flexvar.lib (Windows)
    build/pusher.flexvar.a   (Linux)

    The built libraries are configured for compatibility with other C++ node modules.


    See example subdirectory. The script node rebuild.js will rebuild all the example executables.

    User Manual


    API Documentation




    Unit Tests

    node test

    This will invoke the unittest executable (without having to worry about platform specifics).


    • None

    The library itself has no dependencies. See the build instructions above for required tools to build the library.


    npm install --dev
    node rebuild

    Internally, CMake is used to build the C++ code. As such, the build directory will contain a relevant Makefile or Visual Studio Solution file for the platform. It is often more convenient to use such files directly during development.


    Huh? A C++ NPM module?

    pusher.flexvar is a bit of an experiment in using the node environment and specifically NPM as a "hosting environment" for C++ development. The advantages of this approach:

    • An excellent dependency management system
    • A cross-platform scripting environment

    NPM allows for versioned dependencies, local copies of dependencies (rather than global installs), automatic installs via git repositories, and lots more. Node provides a great environment for creating glue-code and build scripts that are easy to make cross-platform and can hide the details of building the project so focus can remain on development. The above can both be utilized without any direct necessity that the code in development actually be Javascript.

    How do I use a flexvar to share rather than copy data between C++ and JS?

    This isn't directly support. The flexvar library is intended to be lightweight and without direct dependencies on V8. A library for data sharing between C++ and Javascript (while very useful) would look quite different from the current flexvar library.

    Version Changelog


    • gcc support


    • First NPM release




    npm i pusher.flexvar

    Downloadsweekly downloads







    last publish


    • avatar