javascript - Dynamo DB getItem with node js throwing error -


i new javascript , dynamodb. trying perform getitem using aws-sdk javascript in nodejs. primary index of dynamo table cars "name" string.

var aws = require('aws-sdk'); aws.config.region='eu-west-1'; var db = new aws.dynamodb();  var params = { tablename : 'cars',             key : {                     "name" : {                             "s" : "volkswagen dasher"                     },             } }  db.getitem(params, function(err, data) {                 if (err) {                 console.log(err); // error occurred                 }                 else {                 console.log(data); // successful response                 }                 return next();                 }); 

on running above .js file getting following error.

 ubuntu@ubuntu:~/node$ node getitem.js    {}  /home/ubuntu/node_modules/aws-sdk/lib/request.js:30              throw err;                    ^ referenceerror: next not defined      @ response.<anonymous> (/home/ubuntu/node/getitem.js:21:10)      @ request.<anonymous> (/home/ubuntu/node_modules/aws-sdk/lib/request.js:353:18)      @ request.calllisteners (/home/ubuntu/node_modules/aws-sdk/lib/sequential_executor.js:105:20)      @ request.emit (/home/ubuntu/node_modules/aws-sdk/lib/sequential_executor.js:77:10)      @ request.emit (/home/ubuntu/node_modules/aws-sdk/lib/request.js:595:14)      @ request.transition (/home/ubuntu/node_modules/aws-sdk/lib/request.js:21:10)      @ acceptorstatemachine.runto (/home/ubuntu/node_modules/aws-sdk/lib/state_machine.js:14:12)      @ /home/ubuntu/node_modules/aws-sdk/lib/state_machine.js:26:10      @ request.<anonymous> (/home/ubuntu/node_modules/aws-sdk/lib/request.js:37:9)      @ request.<anonymous> (/home/ubuntu/node_modules/aws-sdk/lib/request.js:597:12) 

plz me out. cheers!

glad see you're giving dynamodb try! i'm not sure understand context of code, if goal make simple getitem call, don't need 'return next()' statement. given javascript's event driven nature, these callbacks asynchronous , don't "return" anything. instead, should inspect response (data) , perform action accordingly.

i.e.

dynamodb.getitem(params, function(err, data) {                      if (data) {                         dosomethingwithitem(data.item);                      }                  }); 

also, if you're starting out recommend taking @ document-js-sdk wrapper on top of original sdk allow use literals such "string" instead of {s: "string"}.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Restarting Supervisor and effect on FlaskSocketIO -