If by "returning" you mean "serve as a response to a endpoint
", you can use express
as follows:
const express = require('express');
const fetch = require('node-fetch');
const app = express();
const TOKEN = '[SEU TOKEN]';
app.get('/', async (req, res) => {
try {
const result = await fetch('http://apiadvisor.climatempo.com.br/api/v1/locale/city?name=Joinville&state=SC&token=${TOKEN}');
const { 0: { id } } = result.text();
const body = await fetch('http://apiadvisor.climatempo.com.br/api/v1/forecast/locale/${id}/days/15?token=${TOKEN}');
res.send(JSON.parse(body.text()));
} catch(e) {
console.error(e);
res.status(500).send('Ocorreu um erro interno.');
}
});
app.listen(3000, () => console.log('A aplicação está sendo executada na porta 3000!'));
Installing express
in your application can be done using the command below:
npm install express
And the installation of the node-fetch
module can be done through the command:
npm install node-fetch
The service can be accessed through:
http://localhost:3000/
Note: Since you provided an image instead of the code, typing errors may occur. It is important that you do not put in your question the image of the code but rather the code itself, making it easier for anyone to respond.