Is there a way to dynamically set the IP address in my npm script so I dont have to?


#1

I have a start script:

"start": "meteor run --port 111.111.1.111:3000 --settings settings-local.json",

I like using the IP instead of localhost, then I can connect my iphone and debug webapps by mobile, or I can have my expo react-native app hit the local version of the server code.

But every time I switch locations (home/office) I have to remember to go in my script and change out the hard coded address (it changes depending on whos wifi you’re on). Is there a variable or something that I can plug into my start script so it just grabs whatever the IP is?

It’s not the end of the world but it’s one of those things where you’re like “there has to be a better way”

I know you can get the IP in the code, but I need it in the start script.


#2

You can try this:

"scripts": {
    "start": "meteor run --port `ip route get 8.8.8.8 | awk '{print $NF; exit}'`:3000 --settings settings-local.json"
 }

To test, run this from your command line to ensure you get the correct ip address:

ip route get 8.8.8.8 | awk '{print $NF; exit}'


#3

on a mac right now …