4

I have a node.js application that uses webpack-dev-server, so in my package.json I have this to start it:

...
"scripts": {
    "start": "webpack-dev-server --host 192.168.0.13 --port 3001",
}
...

192.168.0.13 is my local IP address. As my network uses DHCP, is there a variable that I can use instead of my IP address in package.json or webpack.config.js file, so that it will always use my local IP?

Note: I have read that I can use 0.0.0.0, but this is apparently insecure, so is there something else I can use directly in my package.json or webpack.config.js file that will dynamically provide webpack-dev-server with my local IP address?

JoeTidee
  • 24,754
  • 25
  • 104
  • 149

2 Answers2

2

I discovered that the host can be dynamically set within webpack.config.js using the host option:

...
devServer: {
    host: require('os').hostname().toLowerCase(),
    port: 3001,
    ...
},
...
JoeTidee
  • 24,754
  • 25
  • 104
  • 149
0

You can get your IP address inside of package.json with the ipconfig getifaddr en0 command like this:

"start": "webpack-dev-server --host \"$(ipconfig getifaddr en0)\" --port 3001"

iuliu.net
  • 6,666
  • 6
  • 46
  • 69