Created
November 30, 2021 16:49
-
-
Save alperbayram/5111f2e3c870d7afab8e051c99d3e751 to your computer and use it in GitHub Desktop.
getData.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//getData.js | |
import axios from "axios"; | |
export async function getData(number) { | |
const { data: user } = await axios( | |
`https://jsonplaceholder.typicode.com/users/${number}` | |
); | |
const { data: post } = await axios( | |
`https://jsonplaceholder.typicode.com/posts/${number}` | |
); | |
const data = { | |
...user, | |
...post, | |
}; | |
(async () => { | |
try { | |
console.log(data); | |
} catch (e) { | |
console.log(e); | |
} | |
})(); | |
} | |
//app.js | |
/* | |
import {getData} from "./getData.js"; | |
getData(2); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment