npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

read-last-lines-ts

v1.2.1

Published

Efficiently reads the last lines of a file, written in TypeScript for intellisense

Downloads

928

Readme

Read Last Lines (TypeScript)

Read the last lines of a file, written in TypeScript for intellisense, rewritten from the current read-last-lines package by Alexander Bell-Towne.

Copyright © 2020 Speykious


Summary


How to install

  • If you use npm: npm install read-last-lines-ts --save
  • If you use yarn: yarn add read-last-lines-ts

How to use

read-last-lines-ts supports absolute and relative paths since version 1.1.0.

New in v1.2.0: literally 1000 times faster!!!

CommonJS syntax

To read the last 10 lines of a file in utf8 encoding:

const { readLastLines, readLastLinesEnc } = require("read-last-lines-ts")

// You get a Buffer from readLastLines
const buffer = readLastLines("path/to/file", 10)
console.log(buffer.toString("utf8"))

// You can specify a buffer length (default is 4096) ─ example: 50 chars at a time!
// The bufferLength parameter is the length of the internal buffer used for reading
const buffer = readLastLines("path/to/file", 10, 50)

// Alternatively, you can use this curried function for builtin string conversion
// (PS: the optional bufferLength parameter also works here)
const lines = readLastLinesEnc("utf8")("path/to/file", 10)
console.log(lines)

You can choose any encoding from the BufferEncoding enum from fs. Also, the readLastLinesEnc function has been curried so that it is easier to deal with encoding: just make some variable const rll_utf8 = readLastLinesEnc("utf8") and you got yourself a nice short function for reading last lines with utf8 encoding.

ESX syntax

Same example:

import { readLastLines, readLastLinesEnc } from "read-last-lines-ts"

const buffer = readLastLines("path/to/file", 10)
console.log(buffer.toString("utf8"))

// Optional bufferLength argument
const buffer = readLastLines("path/to/file", 10, 50)

// Or:
const lines = readLastLinesEnc("utf8")("path/to/file", 10)
console.log(lines)

You can code in JavaScript, TypeScript, CoffeeScript, whatever is in your best interest.

Miscellaneous

The read-last-lines-ts package is very often 1000s of times faster than the read-last-lines package, as these speed tests indicate:

Test screenshot

When I looked at the code for the read function of the read-last-lines package, there were a lot of things for which I quite didn't understand the motivation behind.

There was absolutely no use of any kind of for loop or while loop, nor any use of async/await. Maybe it was for some kind of backwards-compatibility?

Also, why did they use a custom file system library mz/fs instead of the native fs? Was there no fs back then?

They also used a ton of async behavior on all kinds of places where it wasn't necessary. Maybe that was a factor for how slow it is compared to this modern sync version.

If someone wants to explain any of these things to me, or point out a bug / problem, or request a feature, don't hesitate to raise an issue on the github repo. 😁