I am following this youtube tutorial,
https://www.youtube.com/watch?v=JnvKXcSI7yk&ab_channel=edureka%21
But in my project, the typescript is not working
app.post('/new_contact', function(req, res){
var name = req.body.name;
var phone = req.body.phone;
/* doesn't work
db.insert((name:name, phone:phone, crazy:true), phone, function(err,header ){
if(err){
res.send("Error creating database "+ req.body.dbname);
return;
}
return res.send("contact created successfully");
})
*/
//works
db.insert((name, phone, true), phone, function(err,header ){
if(err){
res.send("Error creating database "+ req.body.dbname);
return;
}
return res.send("contact created successfully");
})
});
When I follow the code in the video I am getting the following error:
Looking forward to hearing from you soon!
Bro , you have a mistake
for db.insert you should provide an object as argument.
instead of :
db.insert((name:name, phone:phone, crazy:true), phone, function(err,header ){
write :
db.insert({name:name, phone:phone, crazy:true}, phone, function(err,header ){
( replace "(" with "{" )
There is a typo in your code. Replace ( with {.
db.insert takes object {} as an argument.
db.insert({name:name, phone:phone, crazy:true}, phone, function(err,header ){
<---somecode--->
}
When you interact with DB, always send an Object. In this case, u need to send name, phone and crazy in the object.
app.post('/new_contact', function(req, res){
var name = req.body.name;
var phone = req.body.phone;
db.insert(({name:name, phone:phone, crazy:true}), phone, function(err,header ){
if(err){
res.send("Error creating database "+ req.body.dbname);
return;
}
return res.send("contact created successfully");
})
})