I'm trying to write to a file on the server side, using react with create-react-app.
First I tried to use the fs module, with the following code (copy-pasted from the doc, except the console log):
const fs = require('fs');
console.log("fs=",fs);
fs.writeFile('acme.js', 'console.log("hello")', function (err) {
if (err) throw err;
console.log('New file acme.js is either created or if exists then updated');
});
The fs object exists, but I get the error TypeError: fs.writeFile is not a function
Then tried to use the file-system module. Here's what I entered:
var fs = require('file-system');
fs.writeFile('path/test.txt', 'aaa', function(err) {"error error"})
Then I get the error TypeError: fs.existsSync is not a function
I also tried a github repository at https://github.com/hurkanyakay/reactjs-nodejs-rest-example whose description looked like what I am trying to do. I get messages when executing the commands suggested on the Frontend, specifically Error: Can't resolve 'glamor/lib/hash' .
There appear to be existing issues on these repositories, I have added the detailed error messages there.
I'm using Windows 10 1803, npm v6.4.1, node v8.12.0
I'm wondering whether there isn't something I've missed, maybe my understanding is lacking? Am I using the wrong modules? Is it just that what I'm trying to do can't be done?