I'm working on a project to make a "data plugin", that will be a very thin node.js server deployed near the user database to talk only with my server through HTTP/REST/JSON and binding with C/C++ SQL API
For the backend SQL queries, I would like to try FFI.
To be as plug'n'play as possible, I don't want to force my future users to understand NPM...
So I would like to use FFI without NPM.
How can I do that ?
If I call "require('./lib/ffi.js") in my node.js app and if I replace the standard require(ref) with require(./ref.js) in your files in the lib, would it work ?
Thanks in advance for your help.
When you run the npm install ffi command, a node_modules directory is created (if not exists previously) and the FFI module is downloaded and built in it.
npm install ffi
You may distribute that node_modules directory beside your own application and use require('ffi') as usual, so that the end users have the module and won't have to run NPM for themselves.
However, that approach has its limits. The FFI module is built for a specific platform (OS+CPU), that is the platform where you run npm install ffi. You cannot move the node_modules from a Windows machine to a Mac (or from some 32bit Linux to 64bit) and expect the FFI module to work — it would have to be rebuilt for that target platform.
Currently that (re)building requires NPM to be run, because the author of the FFI module is not going to pre-build the module for all of its supported platforms on his side (issue #53). So if you are going to support, say, four different platforms (Win32, Win64, Linux32, Linux64), you are to build the FFI module four times (once for each of the supported platforms) and to distribute the four different node_modules directory versions with your application, probably making the corresponding four platform-specific packages of your application + node_modules.
Thank you very much for your help, it's crystal clear !! :)
As you mentionned in a previous "issue", building the stuff for Windows is a nightmare as many huge components have to be downloaded and Microsoft Windows SDK for Windows 7 and .NET Framework 4 is not working on my W7 box.
would you have already built FFI for some platforms ? would this code be available somewhere ?
thanks for your precisions.
I've never built FFI and I do not know if any public FFI builds are available.
There aren't any rebuilt binaries for node-ffi at the moment. Hopefully node will offer some sort of prebuilt binary solution for native addons in the future, but today you need to compile it yourself unfortunately. Nothing's stoping you from pre-compiling it for your supported platforms before shipping it off to your users, so that's one possibility.