Summary:
require('dotenv').config()
Too long, didn't read:
Simply creating a file named .env
won't automatically export variables to your process. To do so in bash or any shell system, you can either use the command
export VUE_APP_STRAPI_HOST=http://localhost:1337/
before running your process, or use
VUE_APP_STRAPI_HOST=http://localhost:1337/ node webpack-dev-server --open --hot
.
If you're looking for a way to access variables from a .env file in your process, consider using dotenv:
require('dotenv').config()
However, keep in mind that this only updates the global variable process.env
with your configuration.
To export variables from a .env file to your environment variables, you can use a shell script like the following:
source_it() {
while read -r line; do
if [[ -n "$line" ]] && [[ $line != \#* ]]; then
export "$line"
fi
done < $1
}
source_it .env
Afterwards, you can run your process as usual:
node ./node_modules/.bin/cross-env NODE_ENV=development webpack-dev-server --open --hot
P.S.
Keep in mind that displaying console.log messages in your browser is unrelated to the Node.js process running webpack-dev-server. To make your process.env
variable accessible globally in your browser, consider using something like DefinePlugin