Created
September 2, 2015 23:11
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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