I just started learning node js and I am stuck with the following (I spent hours looking into stackoverflow but didn't get what I want): I am trying to export some data from node js to a js file.
I have 3 files :
- script.js
- app.js
- data.json
In app.js I coded :
const path = require('path');
const fs = require('fs');
const data = path.join(__dirname, '../data/data.json');
const data = fs.readFileSync(`${data}`, "utf-8");
So till now, all's good. I can get and display the data on the vs terminal. Now I want to export this data and to get it from the script.js file that will feed html with the exported data. So on app.js I added :
module.exports = data;
On script.js, to get data, I coded :
import data from '../src/app.js'
console.log(data)
Then on the browser console I got this error : GET http://localhost:5000/src/app net::ERR_ABORTED 404 (Not Found)
Why do I have this GET method error, as I'm just trying to get some data from app.js to script.js ? Is there a way to get it ?
Thanks for your help !