Skip to main content
The Deno 2 Release Candidate is here
Learn more

Tail a file in Deno

This module provides facility to tail a file in Deno.

Dependencies

This module uses two dependencies from Deno’s standard library:

  • BufReader
  • readStringDelim

Usage

To tail a file, import the Tail class & create a tail object by providing the file name.

import { Tail } from "./mod.ts";

const tail = new Tail("/var/tmp/testFile.txt");

To start tailing, use the start API that returns an async iterable:

for await (const line of tail.start()) {
  //Process line
}

To stop tailing, use the stop API:

tail.close();

Example

Here is a complete example:

import { Tail } from "https://deno.land/x/tail@1.0.0/mod.ts";

const tail = new Tail("/var/tmp/testFile.txt");
for await (const line of tail.start()) {
  console.log("Got a line:", line);
}