0

I need that my code pluses 1 to some numbers, but if, for example, it receives 1, I get 11, not 2.

          fs.readFile(`${dir}/warns/${mentioned.id}.txt`, 'utf8', function(err, data) {
              var x = data;
              var y = 1;
              var z = x + y;
              fs.writeFile(`${dir}/warns/${mentioned.id}.txt`, `${z}`, 'utf8', function(err, result) {
                 if(err) console.log('error', err);
          });
          });
      };
4lon3ly0
  • 17
  • 1
  • 6

1 Answers1

0

You need to parse the text before doing the operation. Like this

var x = parseInt(data, 10);

in javascript string 1 with numeric 1 will concatenate.

Ashish Modi
  • 7,529
  • 2
  • 20
  • 35