Hi @klaus.konstantino you can try path.join(process.cwd(), "server/data/nfts.json")
process.cwd() returns the current working directory, i.e. the directory from which you invoked the node command.
Therefore if the server folder is in the project root, then path.join(process.cwd(), "server/data/nfts.json") should give you the correct path to the nfts.json file
Why not import the JSON in the function? JavaScript supports importing JSON just like importing other JS files. In any case, you can solve the issue using: How to Include Files in Netlify Serverless Functions, but I won’t recommend that in your use-case bcause:
The file system is different in local and AWS Lambda. Figuring out the correct path could be tough.
There’s an easier solution (as I mention, simply import the JSON in your JS file).
@klaus.konstantino No need to use fs.writeFileSync if you use dataPath = require('../data/nfts.json') dataPath = require('../data/nfts.json') should read the json file and the variable dataPath will contain the json data.
Even though you can name variables with any name, instead of using dataPath as variable name a proper name will be nftsData as require('../data/nfts.json') reads the json data and sets it to the variable. It does not return the path.