I need to pass the value of the req.params as a property value to the error object but it returns NaN, I know it's because I've previously parsed the req.params from being a String to being a Number, but I can't find a way to return it the value that ceases to meet the following conditions
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`
});
}
});