Can not Access variables of .env file - environment-variables

In my React app, I was trying to access some variables from .env.local but every time I print It it shows undefined.
// src/.env.local
REACT_APP_SECRET_CODE=123456
// In different component
console.log(process.env.REACT_APP_SECRET_CODE);
output: undefined
Note: I tried to use .env file as well, but did not work.
React Script version is 5.0.1

try this ,
make sure your .env file is in root folder and install dotenv package by using, npm install dotenv

Related

Serverless deploy package

I am trying to bypass the package step and uses the existing package to deploy and update CloudFormation stacks.
I have created serverless package by using following command:
serverless package --package package
Got package directory with the following files
cloudformation-template-create-stack.json
cloudformation-template-update-stack.json
service-api.zip
serverless-state.json
Trying to deploy with following command:
SLS_DEBUG=* serverless deploy --package package
getting below error
ServerlessError: This command can only be run in a Serverless service directory. Make sure to reference a valid config file in the current working directory if you're using a custom config file
at PluginManager.validateServerlessConfigDependency (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:546:15)
at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:474:10)
at /usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:524:24
I have tried with copy serverless.yml into package directory, But no luck
Please execute
SLS_DEBUG=* serverless deploy --package package
from the directory where you've serverless.yml file. It should work.
From the name of the file it looks like you've mis-spelled serveless.yml. Please rename it to serverless.yml.

How to Package files using Ruby

I have three separate files, and I would like to have a script that would install the below files in the local folder
Package Items
https://gitlab.com/darkout/builder/-/raw/master/_data/do-hero-content.yml
https://gitlab.com/darkout/builder/-/raw/master/_includes/do-hero-content.html
https://gitlab.com/darkout/builder/-/raw/master/_sass/modules/do-hero-content.scss
Sample code example
install do-hero
Should install the above three files in the local in the following folders
expected output: to have the files in the local below folder
local > /_data/do-hero-content.yml
local > /_includes/do-hero-content.html
local > /_sass/modules/do-hero-content.scss
Could someone advise me what the best way to execute this is?
Thanks
Shovan
You can write a ruby script called install that downloads these files (Calling curl or HTTPX), then use FileUtils to copy them to the location you wanted:
#!/usr/bin/env ruby
if ARGV[0] == 'do-hero'
# Write code to download these 3 files and copy to folders you want
end

laradock refer to workspace directory path

I have successfully installed Prince via the docker-compose.yml and I see the path + executable I need inside my workspace container but calling it out a number of ways in my Laravel .env will not find that path. In order to use prince I need to tell it where the PRINCE_EXECUTABLE_PATH is via the .env. What is the correct way to hit a directory in the workspace container from the Laravel app? I have tried to set a variable in the Laradock env and refer to it from laradock_workspace_1 and also just put the actual path in the env -- nothing seems to find it. What is the correct way?

React-native run-ios loading environment variables

I want a modern way to manage environment variables for a react native mobile app.
The answer here explains the twelve-factor method style (which I love) which involves installing a babel plugin that transpiles references to
const apiKey = process.env.API_KEY;
to their corresponding values as found in the process's environment
const apiKey = 'my-app-id';
The problem is that in order to run this with a populated environment, I need to set it like
API_KEY=my-app-id react-native run-ios
If I have a .env file with 10-20 environment variables in it, this method becomes unwieldy. The best method I've found so far is to run
env $(cat .env | xargs) react-native run-ios
This is a bit undesirable because developers who want to work on this package have to set up custom shell aliases to do this. This isn't conducive to a good development environment, and also complicates the build and deploy flow for releases.
Is there a way to add a hook to the react-native-cli (or a config file) that populates the process environment first? Like an npm "pre" script, but for react-native.
You can use react-native-config which is a native library and requires a link to work or react-native-dotenv which works just like react-native-config but doesn't require any native link.
It'll work fine with .env files set up, e.g. .env.development with environment variables for process.env.NODE_ENV === 'development'.

Rspec errors in Rails app using Nitrous.io - 'cannot open shared object file'

When I run bundle exec rspec spec/ I get the following messages in the console:
Could not open library 'libgtkmm-2.4': libgtkmm-2.4: cannot open shared object file: No such file or directory.
Could not open library 'libgtkmm-2.4.so': libgtkmm-2.4.so: cannot open shared object file: No such file or directory.
Could not open library 'libgtkmm-2.4.so.1': libgtkmm-2.4.so.1: cannot open shared object file: No such file or directory.
Could not open library 'libgtkmm-3.0': libgtkmm-3.0: cannot open shared object file: No such file or directory.
Could not open library 'libgtkmm-3.0.so': libgtkmm-3.0.so: cannot open shared object file: No such file or directory.
Could not open library 'libgtkmm-3.0.so.1': libgtkmm-3.0.so.1: cannot open shared object file: No such file or directory
But, all of the tests pass and my app works just fine. Can anyone fill me in on what may have happened? Should I just scrap this box and clone my repo into a fresh one? I'm using Ruby 2.0.0p247 and Rails 4.0.2 in a Nitrous.io box. Thanks.
Even though unrelated (thank google for finding this), I have been trying to install Nitrogen for Ubuntu today. I get the same error. Seems like a specific GTK library has gone missing recently from either your system or your distro's repository (if you're even using Linux).
If you're using a Linux system, install the libgtkmm packages and if you're lucky enough, your missing library will be in one of those.
Use in Ubuntu this to install all of them:
sudo apt-get install libgtkmm*
Hope this helps.

Resources