Function fetchData returns a promise and then I'm dealing with that promise in generateURL function by chaining the promise
with .then
however it returns Promise < pending >. Function generateURL should return a string What am I doing wrong?
const fetch = require('node-fetch');
const fetchData = async () => {
return await fetch('https://jsonplaceholder.typicode.com/todos/1');
};
const generateURL = () => {
const baseURL = 'https://cdn.test.com/';
fetchData().then((res) => {
const data = res.json();
console.log('data', data);
const id = data.id;
console.log('id', id);
const generatedURL = `${baseURL}${id}`;
return generatedURL;
});
};