What for?
I was generating JSON reports, with my web page statistics, during each deploy. I thought it will be a good idea to store them in some database and display historical data as charts.
Application has 3 routes:
- GET / - for displaying a dashboard,
- GET /get-data - for getting charts data,
- POST /update-metrics - for sending new metrics which should be saved in a database.
Database: MongoDB Backend: NodeJS Frontend: ChartJS and Vanilla JS with some ES6 features
Application is still in progress.
- Example config file
- Build & run
- Example POST data & request with curl
- Example GET data & request with curl
var Config = {
mongo: {
host: "localhost",
port: 27017
databaseName: 'someDatabaseName',
},
metrics: {
collectionName: 'someCollectionName',
rootMetricName: 'someRootName',
metricsTitles: [
"someNode",
"someNode2"
],
maxResultsDisplayed: 5
}
};
exports.config = Config;
- Run 'npm install'
- Run 'grunt build'
- Run 'node app.js'
Would you like to run tests?
- Run 'grunt tests' - runs all tests
{
"someRootName": {
"someNode": 22,
"someNode2": 33
}
}
curl -H "Content-Type: application/json" http://localhost:3000/update-metrics --data-binary "@example.json"
Simply run app (node app.js) and check http://localhost:3000 in your browser.