I've been looking for an answer on Google, and based on the results found, I am able to check whether a table exists or not in CouchDB, using nano module.
However, when I try to make it a custom function, it always return "undefined" no matter what. Here is the function:
var exists = function( id ) {
this.head( id, function( err, body, header ) {
if ( header[ 'status-code' ] == 200 )
return true;
else if ( err[ 'status-code' ] == 404 )
return false;
return false;
});
}
Call it:
nano.db.create( 'databaseName', function() {
var users = nano.use( 'databaseName' );
console.log( exists.call( users, 'documentToCheck' ) );
});
What exactly was wrong here? I can't seem to figure it out correctly.