My hashkey is a number with the name pid
Here is the code
app.get('/register', (req, res) => {
var params = {
TableName:"passengers",
Item: {
"pid": 55
}
};
console.log("Adding a new item...");
docClient.put(params, function(err, data) {
if (err) {
console.log("errrrrrrr");
console.error("Unable to add item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("succccccc");
console.log("Added item:", JSON.stringify(data, null, 2));
}
});
console.log("Added a new item...");
res.send('<h1>some html</h1>');
})
Neither errrr or succcc gets printed in the logs but both "Adding a new item" and "Added a new item" get printed.
As mentioned in comments, the put
API is asynchronous. So, you should return the response to client when the put is successful or failed.
Please include the res.send
inside the call back method. Alos, please use HttpMethod POST for putting the item rather than GET method. I hope you have just used it for quick testing purpose.
console.log("Adding a new item...");
docClient.put(params, function(err, data) {
if (err) {
console.log("errrrrrrr");
console.error("Unable to add item. Error JSON:", JSON.stringify(err, null, 2));
res.send('<h1>some error html</h1>');
} else {
console.log("succccccc");
console.log("Added item:", JSON.stringify(data, null, 2));
res.send('<h1>some html</h1>');
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With