UNPKG

6.1 kBMarkdownView Raw
1# Couchbase Node.js Client
2
3The Node.js SDK library allows you to connect to a Couchbase cluster from
4Node.js. It is a native Node.js module and uses the very fast libcouchbase
5library to handle communicating to the cluster over the Couchbase binary
6protocol.
7
8## Useful Links
9
10Source - [https://github.com/couchbase/couchnode](https://github.com/couchbase/couchnode)
11
12Bug Tracker - [https://www.couchbase.com/issues/browse/JSCBC](https://www.couchbase.com/issues/browse/JSCBC)
13
14Couchbase Developer Portal - [https://docs.couchbase.com/](https://docs.couchbase.com/nodejs-sdk/3.0/hello-world/start-using-sdk.html)
15
16Release Notes - [https://docs.couchbase.com/nodejs-sdk/3.0/project-docs/sdk-release-notes.html](https://docs.couchbase.com/nodejs-sdk/3.0/project-docs/sdk-release-notes.html)
17
18## Installing
19
20To install the lastest release using npm, run:
21
22```bash
23npm install couchbase
24```
25
26To install the development version directly from github, run:
27
28```bash
29npm install "git+https://github.com/couchbase/couchnode.git#master"
30```
31
32## Introduction
33
34Connecting to a Couchbase bucket is as simple as creating a new `Cluster`
35instance to represent the `Cluster` you are using, and then using the
36`bucket` and `collection` commands against this to open a connection to
37open your specific bucket and collection. You are able to execute most
38operations immediately, and they will be queued until the connection is
39successfully established.
40
41Here is a simple example of instantiating a connection, adding a new document
42into the bucket and then retrieving its contents:
43
44**Javascript:**
45```javascript
46const couchbase = require('couchbase')
47
48async function main() {
49 const cluster = await couchbase.connect(
50 'couchbase://127.0.0.1',
51 {
52 username: 'username',
53 password: 'password',
54 })
55
56 const bucket = cluster.bucket('default')
57 const coll = bucket.defaultCollection()
58 await coll.upsert('testdoc', { foo: 'bar' })
59
60 const res = await coll.get('testdoc')
61 console.log(res.content)
62}
63
64// Run the main function
65main()
66 .then((_) => {
67 console.log ('Success!')
68 })
69 .catch((err) => {
70 console.log('ERR:', err)
71 })
72```
73
74**Typescript:**
75```javascript
76import {
77 Bucket,
78 Cluster,
79 Collection,
80 connect,
81 GetResult,
82} from 'couchbase'
83
84async function main() {
85 const cluster: Cluster = await connect(
86 'couchbase://127.0.0.1',
87 {
88 username: 'username',
89 password: 'password',
90 })
91
92 const bucket: Bucket = cluster.bucket('default')
93 const coll: Collection = bucket.defaultCollection()
94 await coll.upsert('testdoc', { foo: 'bar' })
95
96 const res: GetResult = await coll.get('testdoc')
97 console.log(res.content)
98}
99
100// Run the main function
101main()
102 .then((_) => {
103 console.log ('Success!')
104 })
105 .catch((err) => {
106 console.log('ERR:', err)
107 })
108```
109
110## AWS Lambda
111
112Version 4.2.5 of the SDK significantly reduces the size of the prebuilt binary provided with the SDK on supported platforms. The reduction
113enables the SDK to meet the [minimum size requirements](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html) for an AWS lambda deployment package without extra steps for reducing the size of the package. However, if further size reduction is desired, the SDK provides a script to provide recommendations for size reduction.
114
115**Script:**
116```bash
117npm explore couchbase -- npm run help-prune
118```
119
120**Example output:**
121```bash
122Checking for platform packages in /tmp/couchnode-test/node_modules/@couchbase that do not match the expected platform package (couchbase-linux-x64-openssl1).
123Found mismatch: Path=/tmp/couchnode-test/node_modules/@couchbase/couchbase-linuxmusl-x64-openssl1
124
125Recommendations for pruning:
126
127Removing mismatched platform=couchbase-linuxmusl-x64-openssl1 (path=/tmp/couchnode-test/node_modules/@couchbase/couchbase-linuxmusl-x64-openssl1) saves ~13.31 MB on disk.
128Removing Couchbase deps/ (path=/tmp/couchnode-test/node_modules/couchbase/deps) saves ~45.51 MB on disk.
129Removing Couchbase src/ (path=/tmp/couchnode-test/node_modules/couchbase/src) saves ~0.61 MB on disk.
130```
131
132## Documentation
133
134An extensive documentation is available on the Couchbase website - [https://docs.couchbase.com/nodejs-sdk/3.0/hello-world/start-using-sdk.html](https://docs.couchbase.com/nodejs-sdk/3.0/hello-world/start-using-sdk.html) -
135including numerous examples and code samples.
136
137Visit our [Couchbase Node.js SDK forum](https://forums.couchbase.com/c/node-js-sdk) for help.
138Or get involved in the [Couchbase Community](https://couchbase.com/community) on the [Couchbase](https://couchbase.com) website.
139
140## Source Control
141
142The source code is available at
143[https://github.com/couchbase/couchnode](https://github.com/couchbase/couchnode).
144Once you have cloned the repository, you may contribute changes through our
145gerrit server. For more details see
146[CONTRIBUTING.md](https://github.com/couchbase/couchnode/blob/master/CONTRIBUTING.md).
147
148To execute our test suite, run `make test` from the root directory.
149
150To execute our code coverage, run `make cover` from the root directory.
151
152In addition to the full test suite and full code coverage, you may additionally
153execute a subset of the tests which excludes slow-running tests for quick
154verifications. These can be run through `make fasttest` and `make fastcover`
155respectively.
156
157Finally, to build the API reference for the project, run `make docs` from the
158root directory, and a docs folder will be created with the api reference.
159
160# Support & Additional Resources
161
162If you found an issue, please file it in our [JIRA](https://issues.couchbase.com/projects/JSCBC/issues/).
163
164The Couchbase Discord server is a place where you can collaborate about all things Couchbase. Connect with others from the community, learn tips and tricks, and ask questions. [Join Discord and contribute](https://discord.com/invite/sQ5qbPZuTh).
165
166You can ask questions in our [forums](https://forums.couchbase.com/).
167
168## License
169
170Copyright 2013 Couchbase Inc.
171
172Licensed under the Apache License, Version 2.0.
173
174See
175[LICENSE](https://github.com/couchbase/couchnode/blob/master/LICENSE)
176for further details.