node.js - nodejs如何定时不停的向某个文件写入
ringa_lee
ringa_lee 2017-04-17 16:19:20
0
4
435

nodejs如何定时不停的向某个文件写入,比如每隔2s向log.txt.文件写入一段文本,写入的代码如下:


想实现一个后台不停的写入log,在网页循环的展示log.txt的内容。

ringa_lee
ringa_lee

ringa_lee

reply all(4)
刘奇

Loop: infinite loop setTimeout
Recursive: setTimeout recursive
setInterval timing

伊谢尔伦
    setInterval(()=>{
        /**
         * 文件操作逻辑
         */
    },2000)
左手右手慢动作

If you want to complete this loop operation without accessing the nodejs program through the command line or browser, you can try node-schedule, a scheduled execution module of nodejs, host the project in the background using pm2, and then use the scheduled module Just execute the logic code once in 2S

刘奇

https://github.com/merencia/n...
node 版 crontab

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template