# firstline

> Async npm module for Node JS that reads the first line of a file

Latest version **2.0.2** (published 2018-05-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install firstline
pnpm add firstline
yarn add firstline
bun add firstline
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2018-05-24 |
| First published | 2015-02-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/firstline) |
| Module format | CommonJS |
| Node | >=6.4.0 |
| Dependencies | 0 |
| Unpacked size | 293.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 20 |
| Author | Alessandro Zanardi |
| Maintainers | pensierinmusica |
| Keywords | read, check, file, content, filesystem, io, stream, async, promise |

## Links

- npm: https://www.npmjs.com/package/firstline
- Repository: https://github.com/pensierinmusica/firstline
- Issues: https://github.com/pensierinmusica/firstline/issues
- npm.io page: https://npm.io/package/firstline

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2018-05-24
- 2.0.1 — 2018-05-22
- 2.0.0 — 2018-05-22
- 1.3.1 — 2018-05-22
- 1.3.0 — 2018-04-26
- 1.2.1 — 2016-12-07
- 1.2.0 — 2016-03-09
- 1.1.3 — 2016-03-06
- 1.1.2 — 2016-03-06
- 1.1.1 — 2016-03-06
- 1.1.0 — 2016-03-06
- 1.0.0 — 2015-02-28

## README

# Firstline

[![Build status](https://img.shields.io/travis/pensierinmusica/firstline.svg)](https://travis-ci.com/pensierinmusica/firstline)
[![Test coverage](https://img.shields.io/coveralls/pensierinmusica/firstline.svg)](https://coveralls.io/r/pensierinmusica/firstline)
[![Dependencies](https://img.shields.io/david/pensierinmusica/firstline.svg)](https://www.npmjs.com/package/firstline)
[![Npm version](https://img.shields.io/npm/v/firstline.svg)](https://www.npmjs.com/package/firstline)
[![License](https://img.shields.io/github/license/pensierinmusica/firstline.svg)](https://www.npmjs.com/package/firstline)

## Introduction

Firstline is a [npm](http://npmjs.org) async module for [NodeJS](http://nodejs.org/), that **reads and returns the first line of any file**. It uses native JS promises and streams (requires Node >= v6.4.0). It is well tested and built for high performance.

It is particularly suited when you need to programmatically access the first line of a large amount of files, while handling errors if they occur.

## Install

`npm install firstline`

## Usage

`firstline(filePath, [opts])`

- filePath (String): the full path to the file you want to read.
- opts (Object, optional):
  - encoding (String), set the file encoding (must be [supported by Node.js](https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings)).
  - lineEnding (String), the character used for line ending (defaults to `\n`).

Incrementally reads data from `filePath` until it reaches the end of the first line.

Returns a promise, eventually fulfilled with a string.

## Examples

```js
// Imagine the file content is:
// abc
// def
// ghi
//

firstline('./my-file.txt');
// -> Returns a promise that will be fulfilled with 'abc'.

firstline('./my-file.txt', { lineEnding: '\r' });
// -> Same as above, but using '\r' as line ending.
```

***

MIT License

---
_Source: https://npm.io/package/firstline · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
