Steps to publish npm locally.
- First of all you have your package ready to publish.
- If you are using this for older version of react-native with older npm then you may need to link it manually by executing. If you are using the latest react-native then you have to use the autolinking as new npm does not have any link command anymore (reference below about autolinking).
- npm link {package_name}
- If you are using local repository hosted by CNPM, local-npm, etc. then you need to change the registry which npm is pointing to with the command below. Note: Skip this step if you are not using local repository.
- npm set registry {http://localhost:[port]}
- Generate a tar file by executing this command
- npm pack
- Now change your directory to the root directory of your test project that will use this npm package.
- npm install {path of the tar file you created in step 4}
- If everything is successful then you will be able to see the package you installed in the node_modules folder.
Above is just a summary of the reference I used when working with our react-native library. For more helpful information, please refer to this link - https://medium.com/@debshish.pal/publish-a-npm-package-locally-for-testing or you can also refer to this another website - https://arjun30.medium.com/manually-adding-local-library-project-to-reactnative-app
For autolinking please refer to this website - https://github.com/react-native-community/cli/blob/main/docs/autolinking.md
Additional helpful reference that I found with react-native to use any iOS or Android library - https://betterprogramming.pub/react-native-the-quickest-way-to-use-any-native-ios-or-android-library