Do something for each line of a file with JS

Usage no npm install needed!

<script type="module">
  import foreachline from '';


Online version -


npm install -g foreachline


If you are a javascript fan who loves to do all your tasks with javascript , then foreachline is for you.

To use foreachline , you have to install it from npm and use the following command line.

foreachline src.txt logic.js 


fel src.txt logic.js res.txt

Use foreachline or just fel .


  • src.txt - Source file for data.
  • logic.js - contains logic for mapping the data.
  • res.txt [Optional] - Results will be written to res.txt if specified , else will be written back to src.txt.

What can you do ?

Transform data . Be it a silly to-do list or 50 lines of code , map them the way you want.

Lets say you have the following source file src.txt


All you need to do is writing a JS file to map data on each line to new data.

while creating a JS file , you just need to know one thing . foreachline provides you 2 variables to operate on your data.They are line and lineNumber

Lets say you want to add lines numbers on each line of src.txt Then logic.js would look like

line = lineNumber + "." + line ;

and you will have


If you want to convert them to html list elements

line = "<li>" + line + "</li>" ; 

and you will have


If you want to create JavaScript objects

line = { id : lineNumber , name : line };

and you will have


and I can continue giving examples all night.


Yeah ! We made it to the web browser , as per the plan. Right now , there is no major plans for foreachline.


Please visit the project page to have idea about contibuting towards foreachline.

Whatever you have in your mind , lets discuss. Gitter


This tool is licensed under the MIT License.