Hi,
I want try to use node-mango-client to update some Mango 2.8 datasource properties from outside Mango user interface. Mango instance is running on a RPI3B+.
To achieve this I've done the following:
sudo apt install -y nodejs
node -v
v8.11.1
sudo apt install npm
npm -v
1.4.21
(node:4528) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
cd /home/solergy/MANGO/NODE-JS/
npm install mango-client --save
(node:2363) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
mango-client@0.4.0 node_modules/mango-client
├── uuid@3.1.0
├── moment-timezone@0.5.27
└── moment@2.24.0
after this I've tried this little sample:
const MangoClient = require('mango-client');
const client = new MangoClient({
protocol: 'http',
host: 'localhost',
port: 8810,
rejectUnauthorized: false
});
const DataPoint = client.DataPoint;
const User = client.User;
User.login('myUsername', 'myPassword').then(data => {
console.log(`Logged in as '${data.username}'.`);
return DataPoint.getValue('internal_mango_num_data_points');
}).then(data => {
console.log(`There are ${data.value} data points.`);
// you can perform any arbitrary rest request like this
return client.restRequest({
path: '/rest/v1/data-points/internal_mango_num_data_points',
method: 'GET',
//data: {object}
});
}).then(response => {
console.log(`The data point's name is '${response.data.name}'`);
});
it is the same descripted here:
https://github.com/infiniteautomation/node-mango-client
but I've the following error:
solergy@Tracker_0-1:~/MANGO/NODE-JS/node_modules/mango-client $ node example.js
(node:4926) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token < in JSON at position 3
at JSON.parse (<anonymous>)
at IncomingMessage.response.on (/home/solergy/MANGO/NODE-JS/node_modules/mango-client/src/mangoClient.js:183:62)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
(node:4926) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:4926) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
any idea about where's the problem?