Node.js bindings for nanomsg-NG (NNG) v1.11 using Node-API.
- ✅ Node-API based (ABI-stable across Node.js versions)
- ✅ Async/await support for send/recv operations
- ✅ All major messaging patterns (REQ/REP, PUB/SUB, PUSH/PULL, PAIR, BUS)
- ✅ Binary and text data support
- ✅ Socket options
- ✅ Dialer and Listener support
- ✅ Cross-platform (Linux, macOS, Windows)
-
Node.js >= 16.0.0
-
CMake >= 3.13
-
Build tools:
- Linux:
build-essential,cmake,git - macOS: Xcode Command Line Tools,
cmake(via Homebrew:brew install cmake) - Windows: Visual Studio Build Tools, CMake
- Linux:
-
Clone NNG v1.11 into
deps/nng:
mkdir -p deps
cd deps
git clone --depth 1 --branch v1.11.0 https://github.com/nanomsg/nng.git
cd ..- Install dependencies:
npm install --save-dev node-gyp- Build NNG and the bindings:
chmod +x BulildNNG.sh
bash BulildNNG.shNote: The build process will:
- First build NNG using CMake
- Then compile the Node.js bindings linking against NNG
The bindings use Node-API (N-API) for maximum compatibility across Node.js versions. The project structure:
src/- Native C code using Node-APInng_bindings.c- Main module and core functionssocket.c- Socket-related functionsdialer.c- Dialer functionslistener.c- Listener functions
lib/- JavaScript wrapper APIdeps/nng/- NNG library source (v1.11)
- Send/recv operations are fully async and won't block the Node.js event loop
- Use Buffer objects for best performance with binary data
- For high-throughput scenarios, consider batching messages
- Close sockets explicitly when done to free resources
- Browser storage APIs (localStorage/sessionStorage) not applicable
- Some advanced NNG features not yet exposed
- Context API not yet implemented
Contributions welcome! Please ensure:
- Code follows existing style
- Tests pass (
npm test) - New features include tests
MIT