This is useful if you are running an isolated test in a list of inputs. Examples include solving coding puzzles in your favorite code editor. Or maybe taking a list of CSV inputs and hitting API endpoints with it
First, install nodeJS to the latest stable version. Next, create a blank repo.
In that repo, create two files
001.txt file, copy this data below:
1 2 3 4 5 6 7 8 9 10
We need to add the nodeJS code to read this local file. Here it is:
var fs = require('fs'); var readMe = fs.readFileSync('001.txt', 'utf8').split('\n'); console.log(readMe,"readMe");
nodeJS comes preconfigured with a set of standard library tools you can use. One is called the
fs module, which grants you methods for reading local files. First, you require the module. Next, you need to specify the encoding, in this case
split method. This creates an array seperated by each new line designated by
You need to run the file afterwards. If you use visual studio code, press cmd ` and this will open a terminal.
Type this command and hit enter
$ node 001.js
The resulting execution returns this value:
[ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ]