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

266
Vistas
Why I cannot send a string in send in express?

I have the following code to get data from an external API:

const axios = require('axios');
const express =  require('express');

const app = express()

app.get("/coins", (req, res) => {
    console.log("/coins test");

    axios.get("https://www.cryptingup.com/api/markets")
       .then(resultat=>{
         console.log(resultat.data.markets)
           res = resultat.data.markets
           myS="";

               res.forEach(element=>{
               console.log(element.exchange_id);
               myS=myS+element.exchange_id;
            });

            res.send(myS);
         
       })
       .catch(error => console.log(`error is ${error}`));
})

port = 3000

app.listen(port, ()=>{console.log(`The server has started and is listening on port number: ${port}`);});

when I execute the code I get the following:

error is TypeError: res.send is not a function

I dont know where is my error.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You've overwritten the value of res that was passed into the function with this line of code:

res = resultat.data.markets

So, after doing that the original res is gone so you can't call res.send() any more.

Define your own separately named variable:

app.get("/coins", (req, res) => {
    console.log("/coins test");

    axios.get("https://www.cryptingup.com/api/markets")
       .then(resultat => {
           console.log(resultat.data.markets);
           let markets = resultat.data.markets;
           let myS = "";

           markets.forEach(element => {
               console.log(element.exchange_id);
               myS = myS + element.exchange_id;
           });

           res.send(myS);
         
       })
       .catch(error => console.log(`error is ${error}`));
})

Also, you must declare all variables you use with let or const.


FYI, you could simplify a bit with:

let myS = resultat.data.markets.map(element => element.exchange_id).join("");
res.send(myS);
about 4 years ago · Juan Pablo Isaza Denunciar

0

Your problem is that you are grabbing the "res" object which is passed into the express callback function, but then for whatever reason you reassign it to equal some results from your axios call, essentially removing all of the Express methods on "res".

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