Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

333
Visualizações
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');
over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda