Monday, July 1, 2013

Read a file line by line in node.js

Hi all. Today I decided to add a small functionality to my project: when I start my framework, I run stuff one after the other with a list of commands; I decided to add a functionality that reads a particular file (which I want to be a .k file) and extract the commands from that list. To do so I need some things: Read a file Make sure it's a .k file Split it line by line Execute each line Reading a file in node.js is very simple. We just need to import the fs module and call the function readFile: fs.readFile(cmd[1], 'utf8', function(err,...