I am getting my hands on Node.JS
fetch to understand how it works and then use it.
I have installed node-fetch
and followed some tutorials and saw some videos on the subject, but it is not yet all clear. Even if what is shown works, I still have questions. Here one I need to solve soon. What is the way to simply display the page in the browser?
For example in the code below, I use a fetch to access my site (https://mynicewebsite.example.com), possibly setting some options (headers ....), and then I can log a number of informations using console.log(). But how should I change the code if I simply want the contents of the site (https://mynicewebsite.example.com) to be displayed in the browser?
Just as if I had typed the address directly in the address area of the browser.
Here the code with the fetch call.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
const makeFetchCall = async () => {
const response = await fetch('https://mynicewebsite.com', {
method: 'GET',
headers: {
'Authorization': 'Bearer blahfblahdblahzblah',
//..... // possibly some other things
}
});
}
makeFetchCall();
</script>
</body>
</html>