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

265
Views
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 answers
Answer question

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 Report

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 Report
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!