Code Monkey home page Code Monkey logo

peoplecounter's Introduction

People Counter

This was created for the purpose of helping a user on Reddit. You can find the post here.

The goal is to make a simple application that can count people as they walk by. A sensor will make an HTTP request to this app, and the total people count would be updated live for any people watching the page.

Technology used:

  • NodeJS
  • Express
  • Redis
  • Socket.io

Setup

The code is simple, compact, and well commented for the purpose of teaching. A more fractured file structure is recommended for any serious/scaleable project.

NodeJS should be installed, and you should have access to an instance of Redis.

How to setup and run:

  1. Clone this repository
  2. Locate the repository on your computer and open a terminal in that directory. Type npm install to install the dependencies.
  3. Open .env-template, and follow the steps detailed inside. (Duplicate the file as .env and edit the variables to your liking)
  4. Run the server with node app.js

App Usage

The server is running, assuming you followed the setup steps. You'll now be able to access localhost:3000 and see the basic HTML page.

Increasing/Decreasing the people count

To change the people count, send a POST request to either /increase or /decrease. To ensure security you will need to provide the key you defined in the .env. Here's an example usage for increasing the people count: POST http://localhost:3000/increase?key=MyKey

This would return the new total count in JSON format:

{
  count: 1
}

Reading the people count

This was a route I tossed in the code just for fun. If you send a GET request to /count, you will get the current people count.

For example: GET http://localhost:3000/count

would give the following JSON response:

{
  count: 2
}

peoplecounter's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.