|
| 1 | +# Migrating from Nano 10 to Nano 11 |
| 2 | + |
| 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. |
| 4 | + |
| 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. |
| 6 | + |
| 7 | +## Node.js versions |
| 8 | + |
| 9 | +> ** Nano 11 is a breaking change for users of Node.s 16 or earlier ** |
| 10 | +
|
| 11 | +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: |
| 12 | + |
| 13 | +- If you are using Node.js 18 or newer, use Nano 11. |
| 14 | +- If you need to use Node.js 16 or older, use Nano 10. |
| 15 | + |
| 16 | +Nano 10 may continue to receive some security fixes for a time, but Nano 11 represents the future of this project and at some point, support for Nano 10 will cease. |
| 17 | + |
| 18 | +## Agent options |
| 19 | + |
| 20 | +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. |
| 21 | + |
| 22 | +```js |
| 23 | +const agentOptions = { |
| 24 | + bodyTimeout: 30000, |
| 25 | + headersTimeout: 30000, |
| 26 | + keepAliveMaxTimeout: 600000, |
| 27 | + keepAliveTimeout: 30000, |
| 28 | + keepAliveTimeoutThreshold: 1000, |
| 29 | + maxHeaderSize: 16384, |
| 30 | + maxResponseSize: -1, |
| 31 | + pipelining: 6, |
| 32 | + connect: { |
| 33 | + timeout: 10000 |
| 34 | + }, |
| 35 | + strictContentLength: true, |
| 36 | + connections: null, |
| 37 | + maxRedirections: 0 |
| 38 | +} |
| 39 | +const undici = require('undici') |
| 40 | +const undiciOptions = new undici.Agent(agentOptions) |
| 41 | +const nano = Nano({ url: 'http://127.0.0.1:5984', undiciOptions }) |
| 42 | +``` |
| 43 | + |
| 44 | +> 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. |
| 45 | +
|
0 commit comments