Read file and create loop

Asked

Viewed 146 times

0

I have a txt file with several names in column:

Nome 01
Nome 02
Nome 03...

In the archives. js I need to create a loop so that each name is read and uploaded to a variable for the calculations to be done and saved in a file with the individual name.

The calculation part is already done, but I can’t read the txt file and create the loop.

What I have right now is:

var fs = require("fs"),
d3 = require("d3"),
mkdirp = require("mkdirp");

fs.readFile('file.txt', 'utf-8', function(err, data){
    var linhas = data.split(/\r?\n/);
    linhas.forEach(function(linha){

var flightId = "linha", 


      mkdirp("data", function(err) {
        if (err) console.error(err);
        else {
          fs.writeFile("data/" + flightId + ".tsv", csvFormated);
          fs.writeFile("data/data.geojson", JSON.stringify(geojson));
        }
      });
    } else {
      console.log("Flight data not found");
    }
  });
  • amigo have a look at this article https://codigosimples.net/2016/04/25/ler-um-arquivo-local-usando-html5-e-javascript/

  • Almost that, but I need to run java through Node. Thanks Maycon

  • I was able to do.... var flightId = line,

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.