winreg-native
v1.0.5
Published
Native node.js module for interacting with Windows Registry
Readme
winreg-native
Native Node.js binding for ultra-fast Windows Registry access.
Highlights
- Native C++ binding built with
node-gypandnan. - Dramatic speed improvements over JS-based solutions (claimed 250x–5600x faster depending on operation).
- Promise-first API with synchronous
Syncvariants for blocking operations. - One callback-based method:
watchValuefor change notifications.
Table of contents
- Installation & build
- Quick start
- API reference
- Types & conversions
- Examples
- Building / contributing
- Troubleshooting
- License & credits
Installation & build
Install from npm
npm install winreg-nativeThis module contains native code and must be built for the target Node.js version and platform (Windows only).
- Ensure you have a working Windows build environment and Node.js development toolchain (Python, Visual Studio Build Tools,
node-gyp). - Add the module source to your project or install it as a dependency.
- Install
nan(used by the native code) if not bundled:npm install --save nan.
Typical local build steps from the module root:
npm install # install JS deps (if present)
node-gyp configure
node-gyp buildQuick start
const winreg = require('winreg-native');
(async () => {
const v = await winreg.getValue(winreg.HKLM, 'SOFTWARE\\MyApp', 'InstallPath');
console.log('InstallPath =', v);
})();API reference
Constants
The module exports hive constants:
HKLM— HKEY_LOCAL_MACHINEHKCU— HKEY_CURRENT_USERHKCR— HKEY_CLASSES_ROOTHKU— HKEY_USERSHKCC— HKEY_CURRENT_CONFIG
Async methods (Promise)
All async methods return a Promise.
getValue(hive, key, value)→String | Number | BigInt | Buffer | Array<string>setValue(hive, key, value, data)→BooleandeleteValue(hive, key, value)→BooleandeleteKey(hive, key)→BooleandeleteTree(hive, key)→BooleanenumerateKeys(hive, key)→String[]enumerateValues(hive, key)→Objectmapping{ valueName: convertedValue }
All have synchronous counterparts with Sync suffix.
Synchronous methods (blocking)
Identical signatures to async methods but block the event loop and return directly.
watchValue (callback-based)
watchValue(hive, key, value, callback)
- Watches for changes to a registry value.
callback(err, value)—valueis converted per Types & conversions.
Types & conversions
From Registry → JS (ConvertRegistryValue):
REG_DWORD→Number(unsigned 32-bit)REG_QWORD→BigInt(signed 64-bit)REG_BINARY→BufferREG_MULTI_SZ→Array<string>REG_SZ,REG_EXPAND_SZ→String- Fallback/default →
String(raw data interpreted as UTF-8)
From JS → Registry (ConvertJsValue):
String→REG_SZBoolean→REG_DWORD(0 or 1)BigInt→REG_QWORDif lossless 64-bit, elseREG_SZ(string form)Number→REG_DWORDif fits in unsigned 32-bitREG_QWORDif fits in signed 64-bit- otherwise
REG_SZ(string form)
Important:
- Booleans are always written as
REG_DWORD(0/1) and will be read back asNumber, not astrue/false. - Large numbers beyond JS safe integer range will be returned as
BigInt.
Examples
Read a value (async/await)
const path = await winreg.getValue(winreg.HKLM, 'SOFTWARE\\MyCompany\\MyApp', 'InstallPath');
console.log('InstallPath:', path);Set a value
await winreg.setValue(winreg.HKCU, 'Software\\MyApp', 'Enabled', true);Watch a value
winreg.watchValue(winreg.HKCU, 'Software\\MyApp', 'CurrentVersion', (err, value) => {
if (err) return console.error(err);
console.log('new value:', value);
});Synchronous usage
const v = winreg.getValueSync(winreg.HKLM, 'SOFTWARE\\MyApp', 'InstallPath');
console.log(v);Troubleshooting
- Booleans not returned as booleans — expected behavior; interpret
0/1manually. - Binary data — returned as
Buffer. - Build errors — ensure MSVC Build Tools &
node-gypare set up.
