node js: send get request, save response Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of node js: send get request, save response without wasting too much if your time.

The question is published on by Tutorial Guruji team.

edited, i cut it short.

code variable is assigned

firstly i need to trigger a php script with get request, output shouldn’t be saved "https://flower.nyaizhel.ml/fun/carbon/?code=" + code

then, when the request above completed, send get request to "https://flower.nyaizhel.ml/fun/carbon/shorturl.php?short&code=" + code and save the response to a variable,

for https://flower.nyaizhel.ml/fun/carbon/shorturl.php?short&code=ii it should be 6, see the url

i tried fetch, no result

Answer

You have to await it as text:

const resultValue = await fetch(`https://flower.nyaizhel.ml/fun/carbon/shorturl.php?short&code=${code}`).then(res => res.text());
// (if code === ii, resultValue = "6")
let resultAsInt = parseInt(resultValue);
We are here to answer your question about node js: send get request, save response - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji