[Vuejs]-How to have dynamic .env files instead of hard coded localhost?

0👍

Even if your app url is set to localhost, the application is still accessible, as long as there is no firewall restricting it. You can also access it through 127.0.0.1 or the local IP address assigned to your machine.


The way to get your local ip address depends on your system, but you can just run this in the node console

const { networkInterfaces } = require("os");
const nets = networkInterfaces();

for (const name of Object.keys(nets)) {
  for (const net of nets[name]) {
    if (net.family === "IPv4" && !net.internal) {
      console.log({name , address: net.address});
    }
  }
}

Note that if you’re running this in docker the setting may need to be 0.0.0.0 because 127.0.0.1 is a loopback host.

Leave a comment