Hiding An API Key
Add
.envto.gitignoreInstall dotenv module:
npm install dotenv --save-devInstall dotenv webpack:
npm install dotenv-webpack --save-devAdd
require(‘dotenv').config()before declaring the classAdd the following to
webpack.config.js:
1// add to the top2const Dotenv = require('dotenv-webpack');34// ---56node: {7 fs: 'empty'8},9plugins: [10 new Dotenv()11]
Adding An API Key
Create
.envand add the following in it:API_KEY=_insert api key here_Where needed, replace API key with
process.env.API_KEYRestart npm run watch
If The .env File Is Already Committed:
Commit any code changes
Run
git rm --cached .envRun
git add .andgit commit -m "_insert message here_"
Previous post:
Webpack - Cannot Resolve ‘Fs’ In [Path]
Next post:
Node - Fetch Is Not Defined
Discussion