Build simple Node.js barcode reader applications for both desktop and web using barcode4nodejs and opencv4nodejs.
-
For Windows, you must configure the following environment variables before installing the
opencv4nodejs
package:OPENCV_INCLUDE_DIR
: Points to the directory containing theopencv2
subfolder with header files.OPENCV_LIB_DIR
: Points to the library directory containing the OpenCV.lib
files.
npm install opencv4nodejs barcode4nodejs
Set the license key in the desktop.js
and web.js
files:
dbr.initLicense("LICENSE-KEY")
Run the desktop barcode and QR code scanning app with:
node desktop.js
To scan barcodes and QR codes in any web browser, start the web server and then navigate to localhost:2024
:
node web.js
You may encounter the following error when running the code on Windows, even if the opencv4nodejs.node
file has been successfully built:
node:internal/modules/cjs/loader:1275
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: The specified module could not be found.
\\?\D:\code\nodejs-barcode\examples\opencv\node_modules\opencv4nodejs\build\Release\opencv4nodejs.node
at Object.Module._extensions..node (node:internal/modules/cjs/loader:1275:18)
at Module.load (node:internal/modules/cjs/loader:1069:32)
at Function.Module._load (node:internal/modules/cjs/loader:904:12)
at Module.require (node:internal/modules/cjs/loader:1093:19)
at require (node:internal/modules/cjs/helpers:108:18)
at Object.<anonymous> (D:\code\nodejs-barcode\examples\opencv\node_modules\opencv4nodejs\lib\cv.js:58:8)
at Module._compile (node:internal/modules/cjs/loader:1191:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1245:10)
at Module.load (node:internal/modules/cjs/loader:1069:32)
at Function.Module._load (node:internal/modules/cjs/loader:904:12) {
code: 'ERR_DLOPEN_FAILED'
}
To resolve this issue, check the dependencies of opencv4nodejs.node
with dumpbin
:
dumpbin /dependents node_modules\opencv4nodejs\build\Release\opencv4nodejs.node
Then copy the missing DLL, opencv_world410.dll
, to the directory where opencv4nodejs.node
is located.