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

302
Views
req.params devuelve NaN en la cadena de error devuelta si trato de verificar su tipo de !== número pasándole un parseInt

Necesito pasar el valor de req.params como un valor de propiedad al objeto de error, pero devuelve NaN , sé que es porque previamente analicé los req.params de ser una cadena a ser un número, pero puedo ' encontrar la manera de devolverle el valor que deja de cumplir las siguientes condiciones

 const express = require("express"); const app = express(); const port = 8080; const frase = "Hola mundo como estan"; app.get("/api/letras/:num", (req, res) => { const parseadoParams = parseInt(req.params.num); parseadoParams === 0 && res.json({ error: `the parameter ${parseadoParams} is out of range` }); //HERE IS THE PROBLEM, IN THE TYPEOF typeof parseadoParams !== "number" && res.json({ error: `the parameter ${req.params.num} is not a number`, }); if (parseadoParams < frase.length) { res.json({ letra: frase.split(" ").join("")[parseadoParams - 1] }); // Spaces included // res.json({letra: frase.charAt(req.params.num - 1)}); } else { res.json({ error: `the parameter ${parseadoParams} is out of range` }); } });
about 4 years ago · Juan Pablo Isaza
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!