Open linkangcheng13 opened 5 years ago
能否提供一下 package.json
,应该是你的版本不对。
(1) root@ubuntu:/opt/designiot目录下的package.json, root@ubuntu:/opt/designiot$ ls cloud iotAPP node_modules package-lock.json package.json python www root@ubuntu:/opt/designiot$ sudo cat package.json { "name": "iot-restful-example", "version": "0.0.1", "description": "Internet of Things Example", "author": "", "license": "MIT", "dependencies": { "aws-iot-device-sdk": "^2.2.1", "body-parser": "^1.14.1", "echarts": "^4.2.1", "express": "^4.13.3", "jade": "^1.11.0", "mongodb": "^2.2.33", "mqtt": "^3.0.0", "pm2": "^3.5.0" } } root@ubuntu:/opt/designiot$
(2) root@ubuntu:/opt/designiot/chapter7/lan目录下的package.json, root@ubuntu:/opt/designiot/chapter7/lan$ ls README.md app.js coapServer.js db.js mqttServer.js package.json public views root@ubuntu:/opt/designiot/chapter7/lan$ sudo cat package.json { "name": "iot-restful-example", "version": "0.0.1", "description": "Internet of Things Example", "author": "", "license": "MIT", "dependencies": { "body-parser": "^1.14.1", "coap": "^0.12.1", "express": "^4.13.3", "jade": "~1.11.0", "mongodb": "^2.0.50", "mqtt": "^1.6.0" } } root@ubuntu:/opt/designiot/chapter7/lan$
两个代码里的 MQTT 版本不对。新版本的 MQTT 已经不支持作为 Server 运行了,好像
root@ubuntu:/opt/designiot/chapter7/lan$ node app.js /opt/designiot/chapter7/lan/app.js:93 mqtt.MqttServer(mqttServer).listen(1883, function () { ^
TypeError: mqtt.MqttServer is not a function at Object. (/opt/designiot/www/nodejs/rest-db/chapter7/lan/app.js:93:6)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
root@ubuntu:/opt/designiot/chapter7/lan$