Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8691

nodejsでtail

$
0
0

electron(nodejs)上で特定のファイルをtailする

tailライブラリを使用する。
https://github.com/lucagrulla/node-tail

$ yarn add tail
App.tsx
importReact,{useEffect,useState}from'react'import{render}from'react-dom'import{Tail}from'tail'consttail=newTail('file-path')constApp=()=>{let[texts,setTexts]=useState<string[]>([])useEffect(()=>{tail.on('line',(data:string)=>{texts=[...texts,data]setTexts(texts)})return()=>{tail.unwatch()}},[])return(<>{texts.map((text,index)=>{return(<divkey={index}>{text}</div>
)})}</>
)}

Viewing all articles
Browse latest Browse all 8691

Trending Articles