Home > database >  nodejs - typescript not working in javascript file
nodejs - typescript not working in javascript file

Time:04-30

I am following this youtube tutorial,

enter image description here

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:

enter image description here

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--->
}
  • Related