Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@robertkowalski
Created April 10, 2015 00:34
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 robertkowalski/ad59db3085e76ff27452 to your computer and use it in GitHub Desktop.
Save robertkowalski/ad59db3085e76ff27452 to your computer and use it in GitHub Desktop.
var request = require('request')
var testDbName = 'foobar123' + Math.floor(Math.random() * 10000)
var cookieJar = request.jar()
request({
jar: cookieJar,
method: 'POST',
form: {
name: 'tester',
password: 'testerpass'
},
uri: 'http://localhost:5984/_session'
}, function (er, res, body) {
request({
jar: cookieJar,
method: 'PUT',
json: true,
body: {
id: testDbName,
name: testDbName
},
uri: 'http://localhost:5984/' + testDbName
}, function (er, res, body) {
console.log('create db', body)
request({
jar: cookieJar,
method: 'GET',
json: true,
uri: 'http://localhost:5984/' + testDbName + '/_all_docs?limit=6'
}, function (er, res, body) {
console.log(body)
})
request({
jar: cookieJar,
method: 'GET',
json: true,
uri: 'http://localhost:5984/' + testDbName + '/_all_docs?startkey=%22_design%2F%22&endkey=%22_design0%22&include_docs=true&limit=501'
}, function (er, res, body) {
console.log(er, body)
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment