Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

215
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda