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

283
Views
Eliminar filas específicas de un archivo de texto en NodeJS

Estoy tratando de eliminar una fila específica de un archivo de texto usando NodeJs, pero tengo problemas para hacerlo. ¿Alguien puede ayudarme por favor?

Este es el contenido dentro del archivo de texto y estoy tratando de eliminar el ejemplo 3: ejemplo 3 del archivo de texto.

 example1:example1 example2:example2 example3:example3 example4:example4

Este es el código que debería funcionar pero no lo hace

 const fs = require('fs') const path = require('path') const filePath = path.join(__dirname, '../data/test.txt') const fileData = fs.readFileSync(filePath, 'utf-8').split('\r\n') const position = 3 fileData.splice(position - 1, 1)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe guardar el archivo con fs.writeFile o fs.writeFileSync

Sincrónico:

 const fs = require('fs') const path = require('path') const filePath = '../data/test.txt' const filePath = path.join(__dirname, filePath) const fileData = fs.readFileSync(filePath, 'utf-8').split('\r\n') const position = 3 fileData.splice(position - 1, 1) const dataString = fileData.join('\r\n') fs.writeFileSync(filePath, dataString)

Asincrónico:

 const fs = require('fs') const path = require('path') const filePath = '../data/test.txt' const filePath = path.join(__dirname, filePath ) fs.readFile(filePath, (err, data) => { if (err) throw err const fileData a data.split('\r\n') const position = 3 fileData.splice(position - 1, 1) const dataString = fileData.join('\r\n') fs.writeFile(filePath, dataString, (err) => { if (err) throw err else console.log('file saved') }) })
about 4 years ago · Juan Pablo Isaza Report
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!