Using the below code, I am storing one-time use tokens in a text file, upon being submitted in a POST, the script checks the file to see if it exists and then I need it to remove it. Currently, I got as far as replacing it with a blank line as seen below. How do I remove the blank line afterwards, or just remove the token with the line in the first place? I have used the shift feature before however, this wouldn't apply as the token can be on any line in the text document
var data = fs.readFileSync('tokens.txt', 'utf-8');
if(data.includes(req.body.token)){
var newValue = data.replace(new RegExp(req.body.token), '');
fs.writeFileSync('tokens.txt', newValue, 'utf-8');