TypeError: Cannot read property 'dataSources' of undefined error when I am trying to run rest datasource
Here is my code
module.exports = function(Account) {
var cloudantService;
Account.login = function(next, mode) {
console.log("> Account before create called");
var cloudantService = Account.app.dataSources.cloudant;
cloudantService.login(function(err, response, context){
if (err) throw err;
if (response.error) {
next('> response error');
}
console.log(response);
console.log("Response fetched");
next();
});
};
Account.login();
};
Here is my datasource.json
{
"db": {
"name": "db",
"connector": "memory"
},
"cloudant": {
"name": "cloudant",
"connector": "rest",
"operations": [
{
"template": {
"method": "POST",
"url": "http://xxx.xxxx.com/xxx",
"json": true,
"body": {
"loginId": "smanne",
"password": "xxxxx"
},
"functions" : {
"restLogin":[]
}
}
}
]
}
}