Can't get absolute path of json file in data folder
#239
-
|
My folder structure looks something like this: Root Within scripts, there is a function that edits a JSON file import editJsonFile from 'edit-json-file'
const DIRNAME = process.cwd()
//get the _absolute_ **absolute** path of data.json file
const data = editJsonFile(process.env.JSON_PATH || (DIRNAME + "/data/data.json"))
export function getJSON(){
return data.get();
}
export function writeJSON(callback){
let __data = callback(getJSON());
let keys = Object.keys(__data);
let values = Object.values(__data);
for(var i = 0; i < keys.length; i++){
data.set(keys[i], values[i]);
}
data.save();
return getJSON();
}The edit-json-file npm package needs the absolute path of a json file to be able to edit it. On my localhost it works fine, but on vercel I get an error:
Is there any way I can fix this or access the data folder? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
You can access the base URL via the System Environment Variables. However, our file system is not writable, you might want to try having a database to store this file on to be able to edit it. |
Beta Was this translation helpful? Give feedback.
You can access the base URL via the System Environment Variables. However, our file system is not writable, you might want to try having a database to store this file on to be able to edit it.