Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
nodejs - typescript not working in javascript file

I am following this youtube tutorial,

https://www.youtube.com/watch?v=JnvKXcSI7yk&ab_channel=edureka%21

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!

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

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 "{" )

about 4 years ago · Juan Pablo Isaza Report

0

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--->
}
about 4 years ago · Juan Pablo Isaza Report

0

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");
    })
})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!