N
N
newaitix2018-04-29 14:48:55
Node.js
newaitix, 2018-04-29 14:48:55

Write to file from console?

fs.writeFile('./public/library.js',obfuscationResult.getObfuscatedCode(),function(err){
    fs.readFile('./public/library.js',"utf8",function(error,data){
      fs.writeFile('./public/library.js','/*\n* JavaScript Library v1.1.77\n');
      fs.appendFile('./public/library.js',data);
    });
  });

I take the contents of the file, compress it, save it in the public directory, reopen it, add lines to the beginning of the file.
Question
I am getting the same string "JavaScript Library v1.1.77" added
I want to enter the version manually.
But how can I make the addition of lines to the file only be executed after I enter the version number in the console?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
newaitix, 2018-04-29
@newaitix

The fact is that I already tried several options but they did not work. In particular, the read module.
The recording was made before I entered the data in the console.
Here is an option with readline that works

fs.writeFile('./public/library.js',obfuscationResult.getObfuscatedCode(),function(err){
    fs.readFile('./public/library.js',"utf8",function(error,data){			
      var rl = readline.createInterface({
        input:process.stdin,
        output:process.stdout
      });
      rl.question('What do you think of Node.js? ', (answer) => {
        fs.writeFile('./public/library.js','/*\n* JavaScript Library v'+answer);
        fs.appendFile('./public/library.js',data);
        rl.close();
      });
    });
  });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question