Can't access a json file

Im new to netlify and have this forum which i want to store posts in a json file. the json file is in the netlify/functions folder on my repo and i am accessing the js file which should access it using /.netlify/functions however it says that the json file does not exist in /.netlify/functions

heres the code:
data.json:
{
“technology”: {
“Computer Science”: [
{
“title”: “01010111 00110011 01010011 01000011 01001000 01001111 01001111 01001100 01010011 00100000 01001000 01010100 01001101 01001100 00100000 01010011 01001011 01000101 01001100 01000101 01010100 01001111 01001110 00111010”,
“content”: “01010111 00110011 01010011 01000011 01001000 01001111 01001111 01001100 01010011 00100000 01001000 01010100 01001101 01001100 00100000 01010011 01001011 01000101 01001100 01000101 01010100 01001111 01001110 00111010 00001010 00111100 00100001 01000100 01001111 01000011 01010100 01011001 01010000 01000101 00100000 01101000 01110100 01101101 01101100 00111110 00001010 00111100 01101000 01110100 01101101 01101100 00100000 01101100 01100001 01101110 01100111 00111101 00100010 01100101 01101110 00100010 00111110 00001010 00111100 01101101 01100101 01110100 01100001 00100000 01100011 01101000 01100001 01110010 01110011 01100101 01110100 00111101 00100010 01010101 01010100 01000110 00101101 00111000 00100010 00111110 00001010 00111100 01110100 01101001 01110100 01101100 01100101 00111110 01010000 01100001 01100111 01100101 00100000 01010100 01101001 01110100 01101100 01100101 00111100 00101111 01110100 01101001 01110100 01101100 01100101 00111110 00001010 00111100 01101101 01100101 01110100 01100001 00100000 01101110 01100001 01101101 01100101 00111101 00100010 01110110 01101001 01100101 01110111 01110000 01101111 01110010 01110100 00100010 00100000 01100011 01101111 01101110 01110100 01100101 01101110 01110100 00111101 00100010 01110111 01101001 01100100 01110100 01101000 00111101 01100100 01100101 01110110 01101001 01100011 01100101 00101101 01110111 01101001 01100100 01110100 01101000 00101100 01101001 01101110 01101001 01110100 01101001 01100001 01101100 00101101 01110011 01100011 01100001 01101100 01100101 00111101 00110001 00100010 00111110 00001010 00111100 01101100 01101001 01101110 01101011 00100000 01110010 01100101 01101100 00111101 00100010 01110011 01110100 01111001 01101100 01100101 01110011 01101000 01100101 01100101 01110100 00100010 00100000 01101000 01110010 01100101 01100110 00111101 00100010 00100010 00111110 00001010 00111100 01110011 01110100 01111001 01101100 01100101 00111110 00001010 00111100 00101111 01110011 01110100 01111001 01101100 01100101 00111110 00001010 00111100 01110011 01100011 01110010 01101001 01110000 01110100 00100000 01110011 01110010 01100011 00111101 00100010 00100010 00111110 00111100 00101111 01110011 01100011 01110010 01101001 01110000 01110100 00111110 00001010 00111100 01100010 01101111 01100100 01111001 00111110 00001010 00001010 00111100 01101001 01101101 01100111 00100000 01110011 01110010 01100011 00111101 00100010 01101001 01101101 01100111 01011111 01101100 01100001 00101110 01101010 01110000 01100111 00100010 00100000 01100001 01101100 01110100 00111101 00100010 01001100 01000001 00100010 00100000 01110011 01110100 01111001 01101100 01100101 00111101 00100010 01110111 01101001 01100100 01110100 01101000 00111010 00110001 00110000 00110000 00100101 00100010 00111110 00001010 00001010 00111100 01100100 01101001 01110110 00100000 01100011 01101100 01100001 01110011 01110011 00111101 00100010 00100010 00111110 00001010 00100000 00111100 01101000 00110001 00111110 01010100 01101000 01101001 01110011 00100000 01101001 01110011 00100000 01100001 00100000 01001000 01100101 01100001 01100100 01101001 01101110 01100111 00111100 00101111 01101000 00110001 00111110 00001010 00100000 00111100 01110000 00111110 01010100 01101000 01101001 01110011 00100000 01101001 01110011 00100000 01100001 00100000 01110000 01100001 01110010 01100001 01100111 01110010 01100001 01110000 01101000 00101110 00111100 00101111 01110000 00111110 00001010 00100000 00111100 01110000 00111110 01010100 01101000 01101001 01110011 00100000 01101001 01110011 00100000 01100001 01101110 01101111 01110100 01101000 01100101 01110010 00100000 01110000 01100001 01110010 01100001 01100111 01110010 01100001 01110000 01101000 00101110 00111100 00101111 01110000 00111110 00001010 00111100 00101111 01100100 01101001 01110110 00111110 00001010 00001010 00111100 00101111 01100010 01101111 01100100 01111001 00111110 00001010 00111100 00101111 01101000 01110100 01101101 01101100 00111110”
},
{
“title”: “HMKDJDksaasnpfwuoq9haafcndkjgnsljewghwpzxnvsjdbvuahdsguinvskjp”,
“content”: “Ymnx nx f yjxy fsi mfx gjjs xmnkyji 5 qjyyjwx ktwbfwi”
}
],
“Engineering”: [
{
“title”: “01010100 01000101 01010011 01010100”,
“content”: “01010100 01001000 01001001 01010011 00100000 01001001 01010011 00100000 01000001 00100000 01010100 01000101 01010011 01010100”
}
]
},
“math”: {
“Algebra”: [
{
“title”: “THIS IS A TEST OF THE NEW POSTING SETUP”,
“content”: “THIS IS A TEST OF THE NEW POST SETUP 8/20/2024 4:37 PM”
}
],
“Geometry”: [
{
“title”: “Pythagorean Theorum”,
“content”: “A^2 + B^2 = C^2”
}
],
“Statistics”:
}
}
dataHandler.js:
const fs = require(‘fs’);
const path = require(‘path’);

// Resolve the path to the JSON file relative to the current directory
const filePath = path.resolve(__dirname, ‘data.json’);

exports.handler = async function(event, context) {
try {
// Log the resolved file path
console.log(‘Resolved File Path:’, filePath);

if (!fs.existsSync(filePath)) {
  return {
    statusCode: 404,
    body: JSON.stringify({ error: 'Data file not found' }),
  };
}

const data = fs.readFileSync(filePath, 'utf8');
return {
  statusCode: 200,
  body: data,
};

} catch (error) {
return {
statusCode: 500,
body: JSON.stringify({ error: error.message }),
};
}
};

@Sideswipe5 Due to how you’re loading the file, you would use included_files, see:

https://docs.netlify.com/configure-builds/file-based-configuration/#functions

included_files: list of additional paths to include in the function bundle. Although our build system includes statically referenced files (like require("./some-file.js") ) by default, included_files lets you specify additional files or directories and reference them dynamically in function code

There’s some more information here:

@nathanmartin how would I include it because I currently have:
netlify.toml:
[functions]
included_files = [“./data.json”]
and it still didn’t work

@Sideswipe5 I can’t really advise as I can’t see your files.

I’ve no way of knowing if ["./data.json"] is even a file that exists.

@nathanmartin it does exist in my github repo in the netlify/functions folder I was wondering if that is the proper Syntax for including a file that is in the netlify/functions folder

Asking me is unfortunately simply ‘asking me to read the documentation on your behalf’.

I’ve actually never used the feature, but I’ve advised others to do so, and they tend to report back that it has solved their issue.

I’d just consult the documentation, use the syntax it demonstrates and double check the location so that you’re sure the path to it “being included” is correct, and that the path for it “being loaded” is correct.

@nathanmartin thanks it worked