I'm using a JSON file to mock a database for some testing. I'm calling and modifying this JSON from Next.js API routes.
This is working locally but when I deploy it to Vercel I'm getting a 500 error.
const fs = require('fs');
let users = require('data/users.json');
export const usersDBmock = {
delete: _delete
};
function _delete(id) {
users = users.filter((x) => x.id !== id);
saveData();
}
function saveData() {
fs.writeFileSync('data/users.json', JSON.stringify(users));
}
In my /pages/api endpoint I'm calling
usersDBmock.delete(123);
Error I'm getting
"error": {
"errno": -30,
"syscall": "open",
"code": "EROFS",
"path": "data/users.json"
}
My suspicious is that 'data/users.json'is not the correct path in Vercel but I can figure out how to do it.
Any ideas?