Using environment variables from ~ / .bashrc in "npm start"?

Sorry if this is a duplicate. I tried to find a similar question, but could not. Here's a breakdown:

I need to use the secret key with the package that I create, and I do not want to publish it, so I am trying to set it as a local bash environment variable. In my .bashrc file, I have the following:

# Obviously this is not the REAL key, just an example
MY_KEY="1111111111111111"

And then in my Gulpfile I have a task called "dev". For simplicity, suppose it looks like this:

gulp.task('dev', function () {
  console.log(process.env.SECRET_KEY);
});

Then, to get the secret key in the environment, in my package.json package there is the following:

"scripts": {
  "start": "SECRET_KEY=$MY_KEY gulp dev"
}

, , npm start, gulp undefined . SECRET_KEY=$MY_KEY gulp dev, gulp 1111111111111111. - npm start bash Node. ?

+4
1

, :

MY_KEY="1111111111111111"

:

export MY_KEY
+3

Source: https://habr.com/ru/post/1650697/


All Articles