Node.js implementation of a webhook to store POSTed JSON objects in a MongoDB collection.
This webhook can be used with any data source that posts JSON payloads via HTTP. MongoDB was the logical choice for the backend storage of the captured data since it can store JSON records containing nested objects as is, thus preserving the original structure in MongoDB documents.
After cloning the repository, change to your new repo's root folder and invoke:
npm installThe webhook relies on dotenv for configuration.
The DATES env variable is a space-delimited list of top-level JSON keys that store DateTime (timestamp) information as strings.
By listing them here, the webhook will change them to Date objects so that MongoDB queries can leverage Date-based functions on these fields.
NODE_ENV = development
PORT = 7654
URI = 'mongodb://my_username:my_password@192.168.0.123:27017/my_database?authSource=my_authentication_database'
DB = my_database
COLLECTION = events
ENDPOINT = event
DATES = 'begin_timestamp end_timestamp'
Only the URL env variable needs to be changed for connecting to MongoDB Atlas
URI = 'mongodb+srv://my_username:my_password@cluster0.cnbvep7.mongodb.net/my_database&authSource=admin&authMechanism=SCRAM-SHA-1&retryWrites=true&w=majority'
Note
Make sure you changecluster0.cnbvep7.mongodb.netto the correct hostname for your MongoDB Atlas cluster.
npm start
Upon success you should see:
> jstore@1.0.0 start
> node server.js
Server listening on port 7654
Provide your data source with the appropriate URI. Based on the configuration example above, it would be:
http://192.168.0.123:7654/event
jstore is released under the MIT license.