Firstline is a npm async module for NodeJS, that reads and returns the first line of any file. It uses native JS promises and streams (requires Node >= v4.0.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.
npm install firstline
(add "--save" if you want the module to be automatically added to your project's "package.json" dependencies)
var firstline = require(firstline)
firstline(filepath)
Incrementally reads data from "filepath" until it reaches the end of the first line. Returns a promise, eventually fulfilled with a string.
// Imagine the file content is:
// abc
// def
// ghi
//
firstline('./my-file.txt')
// -> Returns a promise that will be fulfilled with: 'abc'
MIT License
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。