app.get('/write/:fileName', (req, res) => { var formattedfilename = decodeURIComponent(req.params.fileName); fs.open("/home/damner/code/editing_files/" + formattedfilename, 'wx', (err, fd) => { if (err) { if (err.code === 'EEXIST') { res.status(400).send("File already exists"); return; } res.status(500).send("Error: " + err.message + ""); return; } fs.write(fd, '', (err) => { if (err) { res.status(500).send("Error: " + err.message + ""); return; } res.send("File created successfully"); }); }); }); // For Overwriting an existing file: app.get('/ovrwrite/:fileName', (req, res) => { var formattedfilename = decodeURIComponent(req.params.fileName); fs.writeFile("/home/damner/code/editing_files/" + formattedfilename, '', (err) => { if (err) { res.status(500).send("Error: " + err.message + ""); return; } res.send("File overwritten successfully"); }); }); // For Editing an existing file: app.get('/edit/:fileName', (req, res) => { var formattedfilename = decodeURIComponent(req.params.fileName); fs.readFile("/home/damner/code/editing_files/" + formattedfilename, 'utf8', (err, data) => { if (err) { res.status(500).send("Error: " + err.message + ""); return; } // Assuming your editing logic here... let editedData = data; // Placeholder, replace with your editing logic fs.writeFile("/home/damner/code/editing_files/" + formattedfilename, editedData, (err) => { if (err) { res.status(500).send("Error: " + err.message + ""); return; } res.send("File edited successfully"); }); }); });