I am following this youtube tutorial,
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!
CodePudding user response:
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 "{" )
CodePudding user response:
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--->
}