artem_russkikh artem_russkikh - 1 year ago 132
Javascript Question

How to get React Native packager ip from JavaScript?

Is there any way to get dynamicly React Native packager ip with port or full path to bundle -

through JavaScript code? It can be
. It depends on the running device - simulator or real device

Answer Source

I found NativeModules in ReactNative source code and discover scriptURL here:

import { NativeModules } from 'react-native';


const scriptURL = NativeModules.SourceCode.scriptURL;
const address = scriptURL.split('://')[1].split('/')[0];
const hostname = address.split(':')[0];
const port = address.split(':')[1];

It works on simulator and device!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download