You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+58-52Lines changed: 58 additions & 52 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,8 @@ Offical [Apache CouchDB](https://couchdb.apache.org/) library for [Node.js](http
7
7
> Note: Nano >=11.0.0 is a **breaking change for Node.js versions 16 and older**. Nano 11 uses Node.js's built-in "fetch" HTTP client but this is only available in Node.js versions 18 or later. If you are using Node 16 or older then continue using Nano 10.
8
8
> See our [migration guide](migration_guide_v10_to_v11.md) for moving from Nano 10 to Nano 11.
9
9
10
+
> Note: Nano >=12.0.0 is ESM-only, meaning that the `import` syntax is used to load the module instead of `require`.
11
+
10
12
Features:
11
13
12
14
***Minimalistic** - There is only a minimum of abstraction between you and
@@ -26,7 +28,7 @@ or save `nano` as a dependency of your project with
26
28
27
29
npm install --save nano
28
30
29
-
Note the minimum required version of Node.js is 10.
31
+
Note the minimum required version of Node.js is 20.
30
32
31
33
## Table of contents
32
34
@@ -108,21 +110,22 @@ Note the minimum required version of Node.js is 10.
108
110
To use `nano` you need to connect it to your CouchDB install, to do that:
> Note: Supplying authentication credentials in the URL e.g. `http://admin:mypassword@localhost:5984` is deprecated. Use `nano.auth` instead.
115
118
116
119
To create a new database:
117
120
118
121
```js
119
-
nano.db.create('alice');
122
+
nano.db.create('alice')
120
123
```
121
124
122
125
and to use an existing database:
123
126
124
127
```js
125
-
constalice=nano.db.use('alice');
128
+
constalice=nano.db.use('alice')
126
129
```
127
130
128
131
Under-the-hood, calls like `nano.db.create` are making HTTP API calls to the CouchDB service. Such operations are *asynchronous*. There are two ways to receive the asynchronous data back from the library
@@ -184,35 +187,38 @@ You can also see your document in futon (http://127.0.0.1:5984/_utils).
184
187
Configuring nano to use your database server is as simple as:
@@ -251,13 +256,13 @@ To supply customer headers with each request, supply a headers object when start
251
256
252
257
253
258
```js
254
-
constcouch=require('nano')(
259
+
constcouch=Nano(
255
260
{
256
261
url :"http://127.0.0.1:5984/prefix"
257
262
headers: {
258
263
mycustomheader:'42'
259
264
}
260
-
});
265
+
})
261
266
```
262
267
263
268
## TypeScript
@@ -344,7 +349,7 @@ Lists all the CouchDB databases as a stream:
344
349
```js
345
350
nano.db.listAsStream()
346
351
.on('error', (e) =>console.error('error', e))
347
-
.pipe(process.stdout);
352
+
.pipe(process.stdout)
348
353
```
349
354
350
355
### nano.db.compact(name, [designname])
@@ -396,7 +401,7 @@ by the call to `replication.enable`:
396
401
constr=awaitnano.db.replication.enable('alice',
397
402
'http://admin:password@otherhost.com:5984/alice',
398
403
{ create_target:true })
399
-
awaitnano.db.replication.disable(r.id);
404
+
awaitnano.db.replication.disable(r.id)
400
405
```
401
406
402
407
### nano.db.changes(name, [params])
@@ -413,7 +418,7 @@ const c = await nano.db.changes('alice')
413
418
Same as `nano.db.changes` but returns a stream.
414
419
415
420
```js
416
-
nano.db.changes('alice').pipe(process.stdout);
421
+
nano.db.changes('alice').pipe(process.stdout)
417
422
```
418
423
419
424
### nano.db.info()
@@ -429,7 +434,7 @@ const info = await nano.db.info()
429
434
Returns a database object that allows you to perform operations against that database:
430
435
431
436
```js
432
-
constalice=nano.use('alice');
437
+
constalice=nano.use('alice')
433
438
awaitalice.insert({ happy:true }, 'rabbit')
434
439
```
435
440
@@ -505,7 +510,7 @@ The response is an object with [CouchDB cluster information](https://docs.couchd
505
510
Inserts `doc` in the database with optional `params`. If params is a string, it's assumed it is the intended document `_id`. If params is an object, it's passed as query string parameters and `docName` is checked for defining the document `_id`:
Nano supports making requests using CouchDB's [cookie authentication](http://guide.couchdb.org/editions/1/en/security.html#cookies) functionality. If you initialise *Nano* so that it is cookie-aware, you may call `nano.auth` first to get a session cookie. Nano will behave like a web browser, remembering your session cookie and refreshing it if a new one is received in a future HTTP response.
1183
1188
1184
1189
```js
1185
-
constnano=require('nano')({
1190
+
importNanofrom'nano'
1191
+
constnano=Nano({
1186
1192
url:'http://127.0.0.1:5984'
1187
1193
})
1188
1194
constusername='user'
@@ -1237,25 +1243,26 @@ function getrabbitrev(rev) {
You can pipe the return values of certain nano functions like other stream. For example if our `rabbit` document has an attachment with name `picture.png` you can pipe it to a `writable stream`:
0 commit comments