Nodejs module for tailing a file
Clone or download
Pull request Compare This branch is 69 commits behind lucagrulla:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


To install:

npm install tail


Tail = require('tail').Tail;

tail = new Tail("fileToTail");

tail.on("line", function(data) {

tail.on("error", function(error) {
  console.log('ERROR: ', error);

Tail constructor accepts few parameters:

var fileToTail = "/path/to/fileToTail.txt";
var lineSeparator= /[\r]{0,1}\n/; // default is now a regex that handle linux/mac (9+)/windows
var fromBeginning = false;
var watchOptions = {}; // as per node documentations

new Tail(fileToTail, lineSeparator, watchOptions,fromBeginning)
  • fileToTail is the name (inclusive of the path) of the file to tail
  • lineSeparator is the line separator token (default "\n")
  • watchOptions is the full set of options that can be passed to as per node documentation (default: {})
  • fromBeginning force the tail of the file from the very beginning of it instead of from the first new line that will be appended(default: "\n")

The only mandatory one is the first, i.e. the the file you want to tail.

Tail emits two type of events:

  • line
  • error

If you simply want to stop the tail:


And to start watching again:

#Want to fork ?

Tail is written in CoffeeScript.

The Cakefile generates the javascript that is then published to npm.

#License MIT. Please see License file for more details.