Reputation: 141
How can I read a file with nodejs, even json, from url?
My file is on a server. I tried with ftp download but it is very inefficient. Now is working on this, but is very slow for download and running...
I need for this type to get data and put in table.
let project_db;
fs.readFile('public/db/db.json', 'utf8', function (err, data) {
if (err) throw err;
project_db = JSON.parse(data);
console.log(project_db.projects.length);
for(let i = 0; i < project_db.projects.length; i++) {
$('#projectTable tbody').append(`
<tr class="rowT">
<th scope="row" class="scope border-bottom-0">${project_db.projects[i].name}</th>
<td class="border-bottom-0">${project_db.projects[i].date}</td>
<td class="border-bottom-0">${(project_db.projects[i].project_constructii == true) ? "DA" : "NU"}</td>
<td class="border-bottom-0">${(project_db.projects[i].project_hvac == true) ? "DA" : "NU"}</td>
<td class="border-bottom-0">${(project_db.projects[i].project_instalatii_sanitare == true) ? "DA" : "NU"}</td>
<td class="border-bottom-0">${(project_db.projects[i].project_instalatii_electrice == true) ? "DA" : "NU"}</td>
<td class="border-bottom-0">${(project_db.projects[i].project_instalatii_incendiu == true) ? "DA" : "NU"}</td>
<td class="border-bottom-0"><a href="#" class="btn btn-success">Vezi oferte</a></td>
</tr>
`);
}
});
Upvotes: 0
Views: 67