'Can you get the content of a github file with javascript?

Is there any way to get the content of a text file (txt/jss/html/...) with javascript or any other way, inserting it to a variable? (Also jquery is ok) I mean: abc.txt contains some text, that ttext should be stored into a variable. Thanks



Solution 1:[1]

Yeah, it's pretty straightforward all you have to do is change the string a little bit like so, for example here is json file from a github repo

https://github.com/arnav7633/tej.js/blob/main/tsconfig.json

now that string gets changed to

https://raw.githubusercontent.com/arnav7633/tej.js/main/tsconfig.json

The domain changes. Then make a simple axios/fetch query to that URL enter image description here

(async() => {
const res = await axios.get("https://raw.githubusercontent.com/arnav7633/tej.js/main/tsconfig.json")
console.log(res.data)
})()
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1