I am setting up a NodeJS application and i need to get data from etcd
. I am using the nodejs-etcd
module.
The following is how I am attempting to return a value from a closure within a closure:
router.get('/', function(req, res, next) {
var etcd = req.etcd;
var result = etcd.read({key: '/reward/christopher'}, function (err, result, body) {
// parse the json body so that it can be read
object = JSON.parse(body);
// return the value of the key
return object.node.value;
});
console.log(result);
});
However all I ever get is the client connection data from the etcd
object and not the value that I am trying to return:
Client {
version: 'v2',
baseurl: 'http://turtle-host-03.turtlesystems.local:4001/v2',
agent: false }
GET / 500 807.246 ms - 1338
GET /stylesheets/style.css 304 6.856 ms - -
The value from the etcd
server in the callback function is correct, it is just getting it into the outer function.
I am suspect this is a misunderstanding on my part as to how this closure works in the callback for the read method in etcd
.
Update 1
Added code as requested instead of linking to a gist.