Search code examples
cnode.jsnode-ffi

Accessing C function from Node.js


I have a requirement where I have to access a C function and expose it as an API. I am supposed to deploy it on Node.js server. I don't know how to access C function using any node package. I have tried using node-ffi package but at the time of installation it gives me error:

gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: incorrect header check
gyp ERR! stack     at Zlib._binding.onerror (zlib.js:295:17)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\niket_kumar\AppData\Roaming\npm\node_modules\node-ffi
gyp ERR! node -v v0.10.33
gyp ERR! node-gyp -v v1.0.1
gyp ERR! not ok

npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.

Note that I am using Python 2.7 and Windows 7 (32-bit).


Solution

  • Try to use this package to install node-ffi: https://www.npmjs.com/package/ffi. Notice that it's called ffi, not node-ffi.

    Also make sure that you have the version 2.7.3 of Python. node-gyp's GitHub page mentions that 2.7.3 is the recommended version for Windows operating system.