README
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>
`);
});
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.