Skip to content

Instantly share code, notes, and snippets.

@daleharvey
Created November 18, 2014 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save daleharvey/5581d01757a4e4ecfd65 to your computer and use it in GitHub Desktop.
Save daleharvey/5581d01757a4e4ecfd65 to your computer and use it in GitHub Desktop.
// index.js
'use strict';
var app = require('express')();
var PouchDB = require('pouchdb');
require('./routes/db.js')(app, PouchDB);
require('./routes/document.js')(app, PouchDB);
app.listen(5985);
// routes/db.js
'use strict';
var jsonParser = require('body-parser').json({limit: '1mb'});
module.exports = function(app, PouchDB) {
// Create a database
app.put('/:db', jsonParser, function (req, res, next) {
var name = encodeURIComponent(req.params.db);
new PouchDB(name, function (err, db) {
if (err) return res.status(412).send(err);
res.status(201).send({ok: true});
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment