couchdb-mkdb
couchdb-mkdb
makes it easy to create databases and stream couchdb's response.
Installation
$ npm i -S couchdb-mkdb
Usage
Express example
This express route creates new databases on every request.
...
app.post('/', (req, res, next) => {
let name = 'mydb-' + uuid.v1();
let opts = {
host: app.get('couchdb'),
security: {
admins: {names: [req.user.name], roles: []},
members: {names: [], roles: []}
},
auth: app.get('auth')
};
mkdb(name, opts)
.on('error', next)
.on('errorResponse', function(response) {
response.pipe(
res.set(response.headers)
.status(response.statusCode)
);
})
.on('success', function() {
res.send({ok: true});
});
});
API
mkdb(name, [opts], callback)
name
The name of the databaseopts
Optional options object. See belowcallback
Function with the signature fn(error, response)
Available options are:
All other options are passed to the underlaying
http.request()
function.
Events
error(err)
- Emitted on request errorerrorResponse(res)
- Emitted when couchdb returns a paranormal responsesuccess
- Emitted on success
Tests
$ git clone https://github.com/domachine/node-couchdb-mkdb.git
$ cd node-couchdb-mkdb
$ npm i
$ npm test