Skip to content

no-stack-dub-sack/hit-count-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hit-Count-Server

About

This app is a simple Node/Express server with a MongoDB backend designed to be used as an API for easily recording hits to a website. Where web traffic is low, standard analytics services will not effectively record even simple data about your site. This aims to solve that problem so you can see how many people have visited your personal portfolio site or latest pet project!

Be warned, though: you'll only get very simple stats. This app will tell you the following:

  • Total hits to your site
  • The date that you began recording
  • Today's date
  • How many people have visited today
  • Average hits per day

That's it! Short and sweet. Here's a screenshot that illustrates what the frontend of this service will display: image (of course, with a sweet color changing background)

This service is also extensible, so you can keep records on multiple sites at once.

Thanks to @bonham000 for laying the groundwork for this app.

Use:

NOTE: I have this particular repo configured for some apps that I'm tracking, but with minimal (ok, some) effort, this can be fairly easily configured for your own purposes should someone actually stumble upon this and want to use it. Let me know if so, and I'd be happy to point out the lines of code that need modification! 😄 In general, though, here's the process:

  • Manually create an record in MongoDB using the Mongo Shell to initialize tracking (in lieu of proper authorization, this is an easy way of preventing outside users from disrupting the count in any way — the MongoDB query looks for a record based on the name of the site you are tracking. If the query does not return an existing record, nothing happens.) This will look something like this:
db.counters.insert({
  host: 'http://your-site-here.com/',   
  startDate: new Date(),
  total: 0,
  today: {
    date: new Date(),
    count: 0
  }
})
  • Once the app is deployed (I used heroku and MLAB), use axios to make an http POST request in the entry point of your app to the register-count route. For example, in componentDidMount() of App.js in a React app:
axios.post('https://your-deployed-hit-counter.com/register-count')
  .then(() => console.log('count registered'))
  .catch(err) => console.log(err));

Here's a live example (this repo IS this exact deployment), set up for tracking 2 sites: https://hit-count-server.herokuapp.com/

About

simple node server for counting things

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published