I have to insert following data in a DynamoDB table using express framework in a node.js application
register.html
<input type = "text" placeholder="First Name" id = "txtFirstName"><br><br>
<input type = "text" placeholder="Last Name" id = "txtLastName"><br><br>
<input type = "email" placeholder="Email" id = "txtEmail"><br><br>
<input type = "text" placeholder="Phone" id = "txtPhone"><br><br>
<input type = "text" placeholder="Zip Code" id = "txtZip"><br><br>
I understand I need to use express body-parser
as mentioned in this post
But it is not clear to me how to create the JSON that I need to insert in a DynamoDB table using the body-parser
approach described. I can do this with jQuery to read those html items and create a JSON. For example, I need to create a JSON like below:
var paramsInsert = {
TableName:tableName,
Item:{
"email": email,
"info":{
"FirstName": fName,
"LastName": lName,
"Phone": phone,
"ZipCode": zip
}
}
};
This paramsInsert
is eventually passed to DynamoDB to insert into a table like below
insertAtTable(paramsInsert);
How do I create paramsInsert
using the body-parser
approach?
EDIT: Following this link I wrote below code but still not getting the output
app.post('/register.html', function(req, res) {
const { fname, lname, email, phone, zip } = req.body;
console.log(fname)
}