Reputation: 11
I have HTML file as follows below and process.env variables as
process.env.var1='abc'
but once application is loaded the variable is undefined.
res.send(`
<html>
<head>
<link href="${process.env.var1}" rel="stylesheet">
</script>
</head>
<body>
<div id="react-root"></div>
</body>
</html>`);
Upvotes: 1
Views: 3928
Reputation: 95
process.env is a global variable provided by your environment through Node Js. But we don't have Node js in the browser, we are going to use webpack.
So you can use configure webpack DefinePlugin to create global constants
// webpack.config.js
const webpack = require('webpack');
module.exports = {
entry: './index.js',
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': '"production"'
}
})
]
};
//index.js
console.log(process.env);
console.log(process.env.NODE_ENV);
Upvotes: 2