How do I specify include and lib paths to node.js npm

node.js, npm

Solution

The zeromq module can be built as follows (other modules may work the same):

- download the zip file and unpack into a temporary location e.g. `/tmp/zeromq.node-master`

- edit the `binding.gyp` file

- find the section that corresponds with your OS and add your include `-I` and library `-L` paths there.

e.g.

['OS=="linux"', {
  'cflags': [
    '<!(pkg-config libzmq --cflags 2>/dev/null || echo "")',
    '-I/usr/local/zeromq3/include'
  ],
  'libraries': [
    '<!(pkg-config libzmq --libs 2>/dev/null || echo "")',
    '-L/usr/local/zeromq3/lib'
  ],
}],

- Run npm install on the temporary directory: `npm install /tmp/zeromq.node-master`

Problem

I'm trying to install a node.js module (zmq in this case) with npm install. The C lib needed for this module is not installed in a standard location. How do I specify extra include paths and lib paths to npm? I've tried things like "CFLAGS="-I/path/to/include" npm install" with no effect.

Original source

Related problems