Skip to content

Instantly share code, notes, and snippets.

@cliffano
Created September 2, 2015 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffano/71d0f655e5181e5f63a2 to your computer and use it in GitHub Desktop.
Save cliffano/71d0f655e5181e5f63a2 to your computer and use it in GitHub Desktop.
Retrieve all database names in a CouchDB database and create a Couchpenter config.
var fs = require('fs');
var http = require('http');
var url = require('url');
if (process.argv.length !== 3) {
console.error('Usage: node couchdb2couchpenter.js https://host:port');
process.exit(1);
}
var _url = url.parse(process.argv[2]);
var options = {
host: _url.hostname,
port: _url.port,
path: '/_all_dbs/',
method: 'GET'
};
var request = require(_url.protocol.replace(/:$/, '')).request(options, function (response) {
response.on('data', function(data) {
var dbs = JSON.parse(data);
var hash = {};
dbs.forEach(function (db) {
hash[db] = [];
});
var output = JSON.stringify(hash);
console.dir(output)
fs.writeFileSync('couchpenter.json', output);
});
});
request.on('error', function(err) {
console.error(err.message);
});
request.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment