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

93
Vistas
How to access URL parameter in the route function and pass it to db query as an integer parameter?

const getContactByContactId = (request, response) => {
    const p_contact_id = parseInt(request.params.contactId);
    pool.query('SELECT api_getContactByContactId($1)', [p_contact_id], (error, results) => {
    if (error) {
      throw error
    }
    response.status(200).json(results.rows[0].api_getcontactbycontactid)
  })
}

Objective: I am creating a PERN-stack web app with a DB table called "contact" to hold contacts. When the user navigates to "http://localhost:3000/contacts/1", I would like to use the code snippet above (housed in react-app/backend/routes/contacts.js) to query the database by passing the URL parameter as an integer to the plpgsql function called "api_getContactByContactId()".

Error: "invalid input syntax for type integer: "NaN" "unnamed portal parameter $1= '...'"

Suspected Problem: It appears from the error and my research that I am not correctly accessing the the URL parameter from "request".

Question: How can I access the URL parameter in the route function and pass it to my db query as an integer? Thank you in advance for any pointers.

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