Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

446
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda