Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

87
Vistas
Get the number of Requests in Express with Save

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`);
});
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

import { readFileSync, writeFileSync } from "fs";
app.get('/ping',(req, res) => {
    const pingCount = readFileSync("pingCount.txt");
    const newPingCount = parseInt(pingCount) + 1;
    writeFileSync("pingCount.txt", newPingCount.toString());
    res.send(`ping world for ${newPingCount} times`);
});

This should work, but create a pingCount.txt file with text 0 first-

about 4 years ago · Juan Pablo Isaza Denunciar

0

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.

import { readFileSync, writeFileSync, existsSync } from "fs";
app.get('/ping',(req, res) => {
    let pingCount = '';
    if(existsSync("pingCount.txt"))
    {
      pingCount = readFileSync("pingCount.txt");
    }
    
    const newPingCount = `${pingCount} 1`;
    writeFileSync("pingCount.txt", newPingCount);
    res.send(`ping world for ${newPingCount} times`);
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda