Skip to content

Instantly share code, notes, and snippets.

@wilwang
Created July 2, 2012 17:40
Show Gist options
  • Save wilwang/3034508 to your computer and use it in GitHub Desktop.
Save wilwang/3034508 to your computer and use it in GitHub Desktop.
Nano :: create db if not exists
var nano = require('nano')('http://localhost:5984');
var dbName = 'testdb';
var testDb = nano.use(dbName);
nano.db.list(function(error, databases) {
if (error)
return console.log('ERROR :: nano.db.list - %s', JSON.stringify(error));
if (databases.indexOf(dbName) < 0) {
nano.db.create(dbName, function(error, body, headers) {
if (error)
console.log('ERROR :: %s', JSON.stringify(error));
})
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment