Skip to content

Commit e412086

Browse files
author
Glynn Bird
committed
added callback notice to the migration guide
1 parent 72bcb2f commit e412086

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

migration_guide_v10_to_v11.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# Migrating from Nano 10 to Nano 11
22

3-
Nano 10 uses the Axios library as an HTTP/HTTPS client. Keeping up with changes to Axios and its dependencies made maintaining this library a chore, so as of Nano 11 we use Node.js's built-in _fetch_ API as our HTTP client. This makes Nano a _zero dependency_ library which makes for faster installs, easier maintenance and slightly better performance.
3+
The highlights:
44

5-
There are some things to bear in mind if you are switching from Nano 10 to Nano 11, so please consider the following advice carefully before you do.
5+
- Nano 11's HTTP client is replaced with the native Node.js _fetch_ function meaning that Nano 11 only works on Node.js 18 and above.
6+
- Nano no longer supports `requestDefaults` to configure the client options.
7+
- Nano no longer supports callbacks.
68

79
## Node.js versions
810

911
> ** Nano 11 is a breaking change for users of Node.s 16 or earlier **
1012
13+
Nano 10 uses the Axios library as an HTTP/HTTPS client. Keeping up with changes to Axios and its dependencies made maintaining this library a chore, so as of Nano 11 we use Node.js's built-in _fetch_ API as our HTTP client. This makes Nano a _zero dependency_ library which makes for faster installs, easier maintenance and slightly better performance.
14+
1115
Nano 11 is only compatible with Node.js versions 18 and older, because it is only these Node versions that have the [fetch](https://nodejs.org/dist/latest-v18.x/docs/api/globals.html#fetch) HTTP client baked in. See [Node.js's Long-term Support page](https://nodejs.org/en/about/previous-releases) to see which are the currently supported and maintained versions. In short:
1216

1317
- If you are using Node.js 18 or newer, use Nano 11.
@@ -17,6 +21,8 @@ Nano 10 may continue to receive some security fixes for a time, but Nano 11 repr
1721

1822
## Agent options
1923

24+
> ** Nano 11 no longer supports `requestDefaults` to configure the HTTP client **
25+
2026
None of Nano's API has changed _except_ when a user is supplying non-default connection handling parameters. Gone is `requestDefaults` which dates back to the "request" days and instead an optional `agentOptions` can be provided which is documented in the README and in TypeScript.
2127

2228
```js
@@ -43,3 +49,29 @@ const nano = Nano({ url: 'http://127.0.0.1:5984', undiciOptions })
4349

4450
> Note: to supply a custom agent, you will need the [undici](https://www.npmjs.com/package/undici) module as a dependency in your own project. Undici is the library that powers Node.js's _fetch_ API but its "Agent" is not programmatically accessible unless undici is imported separately.
4551
52+
## Callbacks
53+
54+
> ** Nano 11 no longer supports callbacks **
55+
56+
In Nano 10 and earlier, the last parameter to most Nano functions was a callback so you could do:
57+
58+
```js
59+
db.list(function(err, data) {
60+
console.log('response', err, data)
61+
})
62+
```
63+
64+
This was the way asynchronous activity was handled in the early days of Node.js but as of Nano 11 all callbacks are removed and we expect the use of Promises:
65+
66+
```js
67+
db.list().then((data) => { console.log('response', data )})
68+
```
69+
70+
or more commonly, the `await` pattern:
71+
72+
```js
73+
const data = await db.list()
74+
console.log('response', data)
75+
```
76+
77+
If your code makes use of the callback style then **it will not work with Nano 11**: you will need to rewrite your code to use Promises or await, or remain on Nano 10.

0 commit comments

Comments
 (0)