Created
July 2, 2012 17:40
-
-
Save wilwang/3034508 to your computer and use it in GitHub Desktop.
Nano :: create db if not exists
This file contains hidden or 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 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