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

180
Vistas
NodeJS creating File but without text

Hey here is my little script:

for (let i = 0; i < test.length; i++) {
        if(publicKey.startsWith(test[i])) {
            console.log(seed + " =[HIT]= " + publicKey)
            fs.appendFile(publicKey.toString() + '.txt', mnemonic.toString(), function (err) {
                if (err) throw err;
                console.log('Finished!');
              });
              exit();

        } else {
            console.log(seed + " =[FAILED]= " + publicKey)
        }
    }

It does create my file but without any text? I tried to put in random text, but it did not work either. Is there a way to fix this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

for is synchronous, but fs.writeFile isn't. You are immediately launching several fs.writeFile at a time, all the commands are over even before your hard disk woke up and realised what happened.

Either use the synchronous version fs.writeFileSync(...); (not recommended), or use the Promise version and await it :

import * as fs from 'node:fs/promises';

for (let t of test) {
  if (publicKey.startsWith(t)) {
    console.log(seed + " =[HIT]= " + publicKey);
    await fs.appendFile(publicKey.toString() + '.txt', mnemonic.toString());
  } else {
    console.log(seed + " =[FAILED]= " + publicKey)
  }
}

console.log('Finished!');
process.exit();
about 4 years ago · Juan Pablo Isaza Denunciar
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