
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
couchbase-analytics
Advanced tools
Node.js client for Couchbase Analytics
To install the latest release using npm, run:
npm install couchbase-analytics
To install the development version directly from github, run:
npm install https://github.com/couchbase/analytics-nodejs-client
Some more examples are provided in the examples directory.
Connecting and executing a query
const analytics = require('couchbase-analytics')
async function main() {
// Update this to your cluster
// IMPORTANT: The appropriate port needs to be specified. The SDK's default ports are 80 (http) and 443 (https).
// If attempting to connect to Capella, the correct ports are most likely to be 8095 (http) and 18095 (https).
// Capella example: https://cb.2xg3vwszqgqcrsix.cloud.couchbase.com:18095
const clusterEndpoint = 'https://--your-instance--'
const username = 'username'
const password = 'password'
// User Input ends here.
const credential = new analytics.Credential(username, password)
const cluster = analytics.createInstance(clusterEndpoint, credential)
// Execute a streaming query with positional arguments.
let qs = 'SELECT * FROM `travel-sample`.inventory.airline LIMIT 10;'
let res = await cluster.executeQuery(qs)
for await (let row of res.rows()) {
console.log('Found row: ', row)
}
console.log('Metadata: ', res.metadata())
// Execute a streaming query with positional arguments.
qs =
'SELECT * FROM `travel-sample`.inventory.airline WHERE country=$1 LIMIT $2;'
res = await cluster.executeQuery(qs, { parameters: ['United States', 10] })
for await (let row of res.rows()) {
console.log('Found row: ', row)
}
console.log('Metadata: ', res.metadata())
// Execute a streaming query with named parameters.
qs =
'SELECT * FROM `travel-sample`.inventory.airline WHERE country=$country LIMIT $limit;'
res = await cluster.executeQuery(qs, {
namedParameters: { country: 'United States', limit: 10 },
})
for await (let row of res.rows()) {
console.log('Found row: ', row)
}
console.log('Metadata: ', res.metadata())
}
main()
.then(() => {
console.log('Finished. Exiting app...')
})
.catch((err) => {
console.log('ERR: ', err)
console.log('Exiting app...')
process.exit(1)
})
Connecting and executing a query
import { Certificates, Credential, createInstance } from "couchbase-analytics"
async function main() {
// Update this to your cluster
// IMPORTANT: The appropriate port needs to be specified. The SDK's default ports are 80 (http) and 443 (https).
// If attempting to connect to Capella, the correct ports are most likely to be 8095 (http) and 18095 (https).
// Capella example: https://cb.2xg3vwszqgqcrsix.cloud.couchbase.com:18095
const clusterEndpoint = 'https://--your-instance--'
const username = 'username'
const password = 'password'
// User Input ends here.
const credential = new Credential(username, password)
const cluster = createInstance(clusterEndpoint, credential)
// Execute a streaming query with positional arguments.
let qs = "SELECT * FROM `travel-sample`.inventory.airline LIMIT 10;"
let res = await cluster.executeQuery(qs)
for await (let row of res.rows()) {
console.log("Found row: ", row)
}
console.log("Metadata: ", res.metadata())
// Execute a streaming query with positional arguments.
qs =
"SELECT * FROM `travel-sample`.inventory.airline WHERE country=$1 LIMIT $2;"
res = await cluster.executeQuery(qs, { parameters: ["United States", 10] })
for await (let row of res.rows()) {
console.log("Found row: ", row)
}
console.log("Metadata: ", res.metadata())
// Execute a streaming query with named parameters.
qs =
"SELECT * FROM `travel-sample`.inventory.airline WHERE country=$country LIMIT $limit;"
res = await cluster.executeQuery(qs, {
namedParameters: { country: "United States", limit: 10 },
})
for await (let row of res.rows()) {
console.log("Found row: ", row)
}
console.log("Metadata: ", res.metadata())
}
main()
.then(() => {
console.log("Finished. Exiting app...")
})
.catch((err) => {
console.log("ERR: ", err)
console.log("Exiting app...")
process.exit(1)
})
FAQs
The official Couchbase Node.js Analytics Client Library.
We found that couchbase-analytics demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.