How can we connect to Dash DB using HTTP/Request module of node.js and execute R-script code. I am able to do it using Node-RED but like to do it programmatically. Right now I am getting this error:
0530 [App/0] ERR Potentially unhandled rejection [2] Error: EACCES, mkdir '/home/nol'
0530 [App/0] OUT STATUS: 500
0530 [App/0] OUT HEADERS: {""content-type":"text/html; charset=UTF-8","set-cookie":Path=/; Secure; HttpOnly"],"connection":"Close", ""}
0530 [App/0] OUT BODY:
0530 [App/0] OUT An internal error has occurred. The application may still be initializing or the URL used is invalid. Check the URL and try again. For more information, view the server log files.
Below is my code :
var options = {
hostname: 'bluemix05.bluforcloud.com',
host:'50.97.93.115',
port: 8443,
path: ':/console/blushiftservices/BluShiftHttp.do',
method: 'POST',
username: 'xxxxxxxxx',
password: 'xxxxxxxxx',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization' : 'Basic ' + new Buffer(username + ':' + password).toString('base64')
}
};
var postData = querystring.stringify({
'msg' : 'cmd=RScriptRunScript&command=library\(ibmdbR\)\ncon <- idaConnect(\"BLUDB\",\"\",\"\")\nidaInit(con)\nSUB_NUM <- c\(0877777777\)\nPAST_YR_AVG <- c\(300\)\nTestUsageTable1<- data.frame \(SUB_NUM,PAST_YR_AVG,stringsAsFactors=FALSE\)\nsqlSave\(con, TestUsageTable1, rownames=FALSE,safer=FALSE,append=TRUE\)&profileName=BLUDB'
});
var req = http.request(options, function (res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
loggererror.info('STATUS: ' + res.statusCode);
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
loggererror.info('Status: ' + e.message);
});
req.write(postData);
req.end();