1.0.1 • Published 5 years ago

express-visit-counter v1.0.1

Weekly downloads
9
License
MIT
Repository
github
Last release
5 years ago

express-visit-counter

An express middleware that counts the visits of your website.

app.js:

var visitCounter = require('express-visit-counter');

app.use(visitCounter.initialize());

Installation

This is a Node.js module available through the npm registry.

Before installing, download and install Node.js. Node.js.

Installation is done using the npm install command:

$ npm install express-visit-counter

Example

index.js for example:

var visitCounter = require('express-visit-counter').Loader;

router.get('/', async function (req, res, next) {
  let visitorsAltogether = await visitCounter.getCount();
  let visitorsSite1 = await visitCounter.getCount("/site1");
  let visitorsSite2 = await visitCounter.getCount("/site2");

  let visitorsLogAltogether = await visitCounter.getLog();
  let visitorsLogSite1 = await visitCounter.getLog("/site1");

  res.send(`
    <b>visitors altogether:</b> ${visitorsAltogether}<br />
    <b>visitors on site 1:</b> ${visitorsSite1}<br />
    <b>visitors on site 2:</b> ${visitorsSite2}<br />

    <p>
    <b>The whole log as JSON-String:</b><br />
    ${JSON.stringify(visitorsLogAltogether)}
    </p>

    <p>
    <b>The log of site1 as JSON-String:</b><br />
    ${JSON.stringify(visitorsLogSite1)}
    </p>
  `);
});

alt text

Options

app.use(visitCounter.initialize({
  sqlitePath: '<path you want to store the sqlite-file>'
}));

Advice

If your code contains app.use(express.static(...));, it often makes sence to write app.use(visitCounter.initialize()); after these lines so that static js files or css files are not logged.

1.0.1

5 years ago

1.0.0

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago