通过保存获取Express的请求数
我想知道是否有任何方法可以通过ExpressJS在某个路径中获取请求总数?但是我需要保存JSON,就像我想要在JSON或TXT上保存数据一样,但我不知道如何保存数据。
let pingCount = "HERE I MUST ADD Some JS for save on TXT/JSON file and show data if you give request write on JSON +1"
app.get('/ping',(req, res) => {
pingCount++;
res.send(`ping world for ${pingCount} times`);
});
I would like to know if is there any way of getting the total number of request in a certain path with Expressjs? But i need save On JSON like i want save data on JSON or TXT nothing more but i dont know how.
let pingCount = "HERE I MUST ADD Some JS for save on TXT/JSON file and show data if you give request write on JSON +1"
app.get('/ping',(req, res) => {
pingCount++;
res.send(`ping world for ${pingCount} times`);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该有效,但可以创建一个带有文本
0
的pingcount.txt文件。This should work, but create a pingCount.txt file with text
0
first-使用此逻辑,第一个请求= 1次,第二个请求= 11是在背上添加1,而不是1+1,而是1,1,1,1,1。
use this one for this logic, First request = 1 Times and Second Request = 11 is add 1 on back not like 1+1 but like 1,1,1,1,1.