https://github.com/spencertorres/peoplecounter
A simple "People Counter" written in NodeJS. Designed as an example for a reddit user.
https://github.com/spencertorres/peoplecounter
es5 express html iot nodejs socket-io
Last synced: 4 months ago
JSON representation
A simple "People Counter" written in NodeJS. Designed as an example for a reddit user.
- Host: GitHub
- URL: https://github.com/spencertorres/peoplecounter
- Owner: SpencerTorres
- License: mit
- Created: 2018-01-13T04:17:30.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-13T05:19:33.000Z (over 7 years ago)
- Last Synced: 2025-01-10T12:00:11.518Z (5 months ago)
- Topics: es5, express, html, iot, nodejs, socket-io
- Language: JavaScript
- Size: 11.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# People Counter
This was created for the purpose of helping a user on Reddit. You can find the post [here.](https://redd.it/7psv27)
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:
```javascript
{
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:
```javascript
{
count: 2
}
```