Hi !
I have a nuxt 3 app deployed on netlify. I’m trying to write a file to my github repo using this function:
(Here’s the function in server/api/produtcs)
import fs from "fs";
import { resolve } from "path";
import path from "path";
import simpleGit from "simple-git";
const git = simpleGit();
export default defineEventHandler(async (event) => {
if (event.node.req.method === "POST") {
const { fileName, content } = await readBody(event);
const rootDir = process.cwd();
const filePath = resolve(rootDir, `./content/products/${fileName}.md`);
try {
await fs.promises.writeFile(filePath, content);
try {
await git.cwd(rootDir);
await git.add(".");
await git.commit(`Added new file: ${filePath}`);
await git.push();
console.log(`Commited and pushed changes to repository`);
} catch (err) {
console.log("commit error", err);
return {err};
}
return "success";
} catch (err) {
console.log("file error", err);
return {err};
}
} else {
return 'error';
}
});
But I’m getting this error:
- code: “ENOENT”
- errno: -2
- path: “/var/task/content/products/filename.md”
- syscall: “open”
Thanks in advance for your help!