The Node.js® Website
1--- 2title: How to publish a Node-API package 3layout: learn 4--- 5 6# How to publish a Node-API version of a package alongside a non-Node-API version 7 8The following steps are illustrated using the package `iotivity-node`: 9 10- First, publish the non-Node-API version: 11 - Update the version in `package.json`. For `iotivity-node`, the version 12 becomes `1.2.0-2`. 13 - Go through the release checklist (ensure tests/demos/docs are OK) 14 - `npm publish` 15- Then, publish the Node-API version: 16 - Update the version in `package.json`. In the case of `iotivity-node`, 17 the version becomes `1.2.0-3`. For versioning, we recommend following 18 the pre-release version scheme as described by 19 [semver.org](https://semver.org/#spec-item-9) e.g. `1.2.0-napi`. 20 - Go through the release checklist (ensure tests/demos/docs are OK) 21 - `npm publish --tag n-api` 22 23In this example, tagging the release with `n-api` has ensured that, although 24version 1.2.0-3 is later than the non-Node-API published version (1.2.0-2), it 25will not be installed if someone chooses to install `iotivity-node` by simply 26running `npm install iotivity-node`. This will install the non-Node-API version 27by default. The user will have to run `npm install iotivity-node@n-api` to 28receive the Node-API version. For more information on using tags with npm check 29out ["Using dist-tags"][]. 30 31## How to introduce a dependency on a Node-API version of a package 32 33To add the Node-API version of `iotivity-node` as a dependency, the `package.json` 34will look like this: 35 36```json 37"dependencies": { 38 "iotivity-node": "n-api" 39} 40``` 41 42> As explained in 43> ["Using dist-tags"][], unlike regular versions, tagged versions cannot be 44> addressed by version ranges such as `"^2.0.0"` inside `package.json`. The 45> reason for this is that the tag refers to exactly one version. So, if the 46> package maintainer chooses to tag a later version of the package using the 47> same tag, `npm update` will receive the later version. This should be acceptable 48> version other than the latest published, the `package.json` dependency will 49> have to refer to the exact version like the following: 50 51```json 52"dependencies": { 53 "iotivity-node": "1.2.0-3" 54} 55``` 56 57["Using dist-tags"]: https://docs.npmjs.com/getting-started/using-tags