Reputation: 1
I am using nodejs 14 and couchdb database 3.1.1 I am trying to connect and display list of couchdb databases using nodejs but following error occur
const NodeCouchDb = require('node-couchdb');`
const couch = new NodeCouchDb();
// node-couchdb instance with Memcached
const MemcacheNode = require('node-couchdb-plugin-memcached');
const couchWithMemcache = new NodeCouchDb({
cache: new MemcacheNode
});
// node-couchdb instance talking to external service
const couchExternal = new NodeCouchDb({
host: 'couchdb.external.service',
protocol: 'https',
port: 5984
});
// not admin party
const couchAuth = new NodeCouchDb({
auth: {
user: 'admin',
pass: 'godhelp'
}
});
couch.listDatabases()
.then(
dbs => dbs.map(...),
err => {
// request error occured
});
ERROR After Compiled :
dbs => dbs.map(...),
^
SyntaxError: Unexpected token ')'
at wrapSafe (internal/modules/cjs/loader.js:988:16)
at Module._compile (internal/modules/cjs/loader.js:1036:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47
Upvotes: 0
Views: 181
Reputation: 1385
I think there is a syntax error in your code, but more fundamentally node-couchdb
seems to be an inactive library that has not been updated in more than four years. I would recommend using nano, which is the official Apache CouchDB NodeJS library.
Here's a simple NodeJS script (index.js
) using nano to list your databases.
const nano = require('nano')(process.env.COUCH_URL)
const main = async function() {
const response = await nano.db.list()
console.log(response)
}
main ()
You will need to create an environment variable called COUCH_URL:
export COUCH_URL="http://user:password@localhost:5984"
and then run the script:
node index.js
#[ 'deeds' ]
Upvotes: 2