A NodeJS API serving internet connection statistics from MongoDB to a React front end, with D3 data visualization.
This app was written as an internal tool for Nashville Software School to display periodic internet speed test data in an easily navigable interface.
Prior to creation of this app I had a long-running script running speedtest-cli and storing hourly speed test information in a simple text file. The import.js
file in the utilities directory was crafted to parse this file and submit them via an HTTP POST to /speedtest
for storage in MongoDB.
Get requests to /speedtest
initiate a new speed test via speedtest-cli and save the returned data to MongoDB.
- Airbnb's react-dates date range picker component.
- React D3's LineTooltip D3 line graph component.
- Install NodeJS
- Install speedtest-cli
- Install MongoDB
- Start MongoDB by running
mongod
in a terminal - Clone down this repository
- In a terminal within the repository directory:
- Install required Node modules by running
npm install
- Generate output files by running
./node_modules/.bin/webpack
- Start the server by running
node server.js
- Install required Node modules by running
- In the browser of your choice, go to
http://localhost:3000/speedtest
a few times to populate the database with some speed test results. - For gathering periodic results you could write a simple cron job running
curl
orwget
to hithttp://localhost:3000/speedtest
hourly. - Navigate to
http://localhost:3000
to view the visualization of the speed test data in the database. - The top day, week, month & year time span buttons control the span of time displayed in the graph.
- Left and right navigation buttons jump forward and back in time by the amount selected by the time span buttons.
- Clicking the displayed dates opens a calendar chooser to select a custom time range for display.
http://localhost:3000/api/
- provides hourly speed test data for the current day.http://localhost:3000/api/day/<date>
- provides hourly speed test data for the specified<date>
provided inYYYYMMDD
format.http://localhost:3000/api/week/<date>
- provides hourly speed test data for the specified week beginning on the<date>
provided inYYYYMMDD
format.http://localhost:3000/api/month/<month>
- provides speed test data summarized by day for the specified<month>
provided inYYYYMM
format.http://localhost:3000/api/year/<year>
- provides speed test data summarized by week for the specified<year>
provided inYYYY
format.http://localhost:3000/api/span/<start_date>/<end_date>
- provides speed test data for the time span between<start_date>
and<end_date>
, both provided inYYYYMMDD
format.
The file src/config.js
contains a configuration object for the React front end.
- apiurl - hostname:port for connecting to the API. Default of
localhost:3000
. - firstscan -
YYYY-MM-DD
formatted date string for the first scan in the database. Default of2016-04-25
.
Several environment variables can be used for additional configuration.
- MONGODB_USER - Username for connecting to MongoDB. Defaults to empty string.
- MONGODB_PASS - Password for connecting to MongoDB. Defaults to empty string.
- MONGODB_HOST - URL for MongoDB connection. Defaults to
localhost
. - MONGODB_PORT - Port used for connecting go MongoDB. Defaults to
27017
. - PORT - Port the Node web server listens on. Defaults to
3000
.