i want do display the data inside this url on my node stand out but it display none , there is something i do wrong in my code
const extractRefDefaultSchema = async (data) => {
const url = "https://mos.esante.gouv.fr/NOS/TRE_R81-Civilite/FHIR/TRE-R81-Civilite/TRE_R81-Civilite-FHIR.json"
https.get(url,(res) => {
let body = "";
res.on("data", (chunk) => {
body = chunk;
});
res.on("end", () => {
try {
let json = JSON.parse(body);
// do something with JSON
} catch (error) {
console.error(error.message);
};
});
}).on("error", (error) => {
console.error(error.message);
});
console.log("extractRefDefaultSchema");
};
CodePudding user response:
You can use fetch API for do this :
fetch(url)
.then((res)=> res.json())
.then((json) => {
let dataJson = JSON.parse(json)
})
CodePudding user response:
You can achieve the same with axios, it would be much simpler.
Code:
let axios = require("axios")
axios.get("https://mos.esante.gouv.fr/NOS/TRE_R81-Civilite/FHIR/TRE-R81-Civilite/TRE_R81-Civilite-FHIR.json").then((res) => {
let jsonData = res.data
})