http-store
v0.6.1
Published
Generic DataStore Using HTTP Verbs
Downloads
6
Readme
#HTTP Store
HTTP Key-Value Store on top of MongoDB
##Features
- Connect to a MongoDB Instance using HTTP and Web Sockets
- Already Compatible with zillions of applications and devices that already speak these standards
- Send data between http and websocket clients
##Other Docs:
##Prerequesites Befor you deploy anywhere, you must have a mongodb server instance running somewhere. Mongo Lab provides this as a service for free.
##Installation
###Remote
####Deploy on Heroku
- Click Here:
- Use Mongo DB credentials to fill out form and follow instructions.
The Procfile includes the verbose (-v) command line argument, so if deploying straight to heroku frome this repository and you have the heroku toolbelt, you may access the application's output via
heroku logs --tail
If you wish to disable this, you may modify the program (see below) and push directly to heroku.
###Locally
####Pre Requesites Node and npm are required to run this locally. Installing node will automatically install npm. Git is also necessary.
####Command Line Application x
- Download and install the CLI app via npm:
npm install -g http-store
- Run with command line arguments
http-store --db-url=mongodb://username:[email protected]:27017/database
- Or run with enviromnem variables
export DB_URL=mongodb://username:[email protected]:27017/database && http-store
####Install via git and npm
- In a terminal type:
git clone git clone https://github.com/johnhenry/http-store.git
cd http-store
npm install
#####Running via npm
- In a terminal type:
npm start
By default, the server will run at 127.0.0.1:8080
Options will be set via environmental variables.
#####Running via node
- In a terminal type:
node server
OR
node server.js
By default, the server will run at 127.0.0.1:8080
Options can be set via command line arguments and/or environmental variables.
#####Running via foreman
If you have the heroku toolbelt installed, you can take advantage of foreman to run your app locally.
- In a terminal type:
foreman start
By default, the server will run at 127.0.0.1:5000
Options will be set via an optional .env file located in the root directory. Command line parameters may be set by modifying the Procfile file.
###Node package
Http store can also be mounted as a router in other node (express) applications.
####Import store object
Supply options to create http-store object object. Note: database options must be supplied when creating object. Other options are, well... optional.
var options = {
//...db options required
}
var store = require('http-store')(options);
####Mount to express application server
Mount at express point just like any other router
< express app >.use(mountPoint, store);
####Mount store object to server Mount the sockets to the server by calling the < store instance >.mountSocket method. Note: can be attached to any http server, not just an express instance.
var server = < http or express app server >;
store.mountSocket(server, [mount point = "/"]);
####Full example
var httpPort = 8080;
var app = require('express')();
var store = require('http-store')(
{
DB_URL : "mongodb://username:[email protected]:27017/database"
}
);
app.use("/mount/point", store);//Mount database
store.mountSocket(
app.listen(httpPort),
"mount/point");//MountSocket
#####Connect
curl -x PUT <server location>/mount/point/:KEY Hello
curl -x GET <server location>/mount/point/:KEY
wscat -c <server location>/mount/point/:KEY