Trying to create a blog-like application using svelte/sapper and so I'm currently writing the post to a file as a JSON object. However, when I try and use fs, I get the following error:
Uncaught ReferenceError: require is not defined
The file below is in the src/routes folder and is what handles the file writing function:
_write.js
function writeFile(obj) {
var fs = require("fs");
fs.writeFile('C:/Users/Toby/Documents/GitHub/political-web/src/routes/_posts.js', 'const posts = ' + obj + '; export default posts;', function (err) {
if (err) throw err;
console.log('Done!');
});
}
export default writeFile;
Any ideas as to what I'm doing wrong?