Tuesday, March 3, 2020

how to fix "TypeError: zmq.socket is not a function" with Node.js in Windows 10?

i just try to use ZEROMQ for a simple publish/subscribe Message passing app.

when i run the app with Node myApp.js. the app thrown an exception

C:\node\microservices\zmq-watch-pub.js:6
const publisher=zmq.socket('pub');     

TypeError: zmq.socket is not a function
    at Object.<anonymous> (C:\node\microservices\zmq-watch-pub.js:6:21)
    at Module._compile (internal/modules/cjs/loader.js:1139:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1159:10)
    at Module.load (internal/modules/cjs/loader.js:988:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47


 I am running in the windows 10 environment and i install zeromq@4.3.2

 "dependencies": {
    "zeromq""4.3.2"
  }

 i already encounter an error during the npm install  zeromq@4.3.2, i have to install verison 5 to avoid the error   npm install  zeromq@5

here is my current zeromq package

 "dependencies": {
    "zeromq""^5.2.0"
  }

Now i can launch the app and start monitoring the file change.

PS C:\node\microservices> node zmq-watch-pub.js target.txt
Listening for zmq subscribers....

1 comment: