0

How can I get the value from a string and write it in an output text file more than one time with it making new lines every time? So I am trying to make a demo for how to save like user input in HTML to a text file using javascript, but I am not trying to do it at the moment, I am trying to do the same thing but from the console user input using readline-sync, the problem isn't in the module or anything else, the problem is when I for example type 'test' in the console it saves 'test' to a text file, but when I do the same process with another word, let's say 'hello' it removes 'test' and writes 'hello', I tried using the \n function but it didn't help, the code is down below:

const fs = require('fs')
const readline = require('readline-sync');
var userinput = 0;
userinput = readline.question(`test\n`);
fs.writeFile('Output.txt', userinput + "\n", (err) => {
      
    if (err) throw err;
})
  • Is this in node, or client side JS? If it's node, you should add the `node.js` tag, if it's client side then I don't believe modifying files on the users system is possible (without significant setup on the target system to disable built in security) – DBS Nov 11 '21 at 14:31
  • I don't really understand the last part but I suppose it's node, and I am not very experienced in node sow how can I add the Node.js tag? – Braketsss Nov 11 '21 at 14:42

0 Answers0