Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

447
Views
NodeJS - Removing a variable from a text file (Replacing with nothing then removing the blank line)

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');
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!