https://github.com/jhen0409/rn-host-detect
Get correctly `localhost` on Android emulator for React Native.
https://github.com/jhen0409/rn-host-detect
Last synced: 4 days ago
JSON representation
Get correctly `localhost` on Android emulator for React Native.
- Host: GitHub
- URL: https://github.com/jhen0409/rn-host-detect
- Owner: jhen0409
- License: mit
- Created: 2017-01-27T05:06:34.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-11-03T09:08:26.000Z (almost 6 years ago)
- Last Synced: 2025-09-02T19:51:40.555Z (about 1 month ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 16
- Watchers: 4
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# rn-host-detect
> Get correctly `localhost` on Android emulator for React Native
On Android emulator, if you want to connect any servers of local, you will need run `adb reverse` on your terminal. This module made it easier, you can get the localhost IP of host machine directly (`10.0.2.2`, Genymotion: `10.0.3.2`).
This was done in the following projects:
* [remote-redux-devtools](https://github.com/zalmoxisus/remote-redux-devtools/blob/fbb169173c235eceb136a02a52c6f36b64297910/src/utils/reactNative.js)
* [reactotron-react-native](https://github.com/infinitered/reactotron/blob/f5de09955b870a90cc772bf6c5139ef8e3ecbbba/packages/reactotron-react-native/src/get-host.js)That's why you don't need `adb reverse` when you're using these modules on Android emulator.
## Installation
```bash
$ npm i rn-host-detect --save-dev
```## Usage
```js
const getHostForRN = require('rn-host-detect')// '10.0.2.2' or '10.0.3.2' on Android
getHostForRN('localhost')// '192.168.1.111', only convert localhost (or 127.0.0.1) to host IP
getHostForRN('192.168.1.111')
```## License
[MIT](LICENSE.md)