function mqtt_messsageReceived(topic, message, packet)
{
var nano = require("nano")("http://localhost:5984");
var http = require("http");
var fields = message.toString().split("#");
console.log('Topic=' + topic + ' Message=' + message);
const selectClient=peers.get().server;
var server = http.createServer(function (request, response) {
nano.db.save("mylibrary", function (err, body, header) {
if (err) {
response.writeHead(500, { "Content-Type": "text/plain" });
response.end("Database creation failed. " + err + "\n");
} else {
response.writeHead(200, { "Content-Type": "text/plain" });
response.end("Database created. Response: " + JSON.stringify(body) + "\n");
}
});
});
console.log("Server running at http://i:5984/");
}
运行此代码时,出现错误:
Error: Cannot find module 'promised-io/lib/promise'
at Function.Module._resolveFilename (module.js:326:15)
at Function.Module._load (module.js:277:25)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/broker1/Desktop/node_modules/couchdb/lib/couchdb.js:2:20)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
并且当我尝试安装此模块时出现另一个错误,因此我想更正此代码以使用node.js将数据存储在沙发上。