I am still learning about env. I'm not sure why it's not working. I have two files in my root project folder. '.env.local' and '.env'. And, the values for .env aren't being processed. However, .env.local is working fine. I believe I followed the same format.
For the .env file, if I just write them on the page and expose them, then they work just fine.
What am I missing here, this is on a NEXTJS app. In vercel I just added Environmental variable to their built in mechanism.
In my code I wrote this to get the value.
env local file
NEXT_PUBLIC_GOOGLE=xxxxxxxxxx
_app.js
my env file
MAILCHIMP_PUBLIC_USERNAME=xxxxx
MAILCHIMP_PUBLIC_DOMAIN=xxxx
MAILCHIMP_PUBLIC_POST=xxxxxxxxxxxxxxxxxxxx&
MAILCHIMP_PUBLIC_ID=xxxxxxxx
I think .env.local is overriding the other files. Also remember to add NEXT_PUBLIC_ to the variables. After editing the .env file you should stop and restart the development server. In your case you should do the following
NEXT_PUBLIC_MAILCHIMP_PUBLIC_USERNAME=xxxxx
NEXT_PUBLIC_MAILCHIMP_PUBLIC_DOMAIN=xxxx
NEXT_PUBLIC_MAILCHIMP_PUBLIC_POST=xxxxxxxxxxxxxxxxxxxx
NEXT_PUBLIC_MAILCHIMP_PUBLIC_ID=xxxxxxxx
Did You read exactly the next.js docs about Environment Variables ? ;-)
It happens because as we can read in next.js docs:
In general only one .env.local file is needed. However, sometimes you
might want to add some defaults for the development (next dev) or
production (next start) environment.
Next.js allows you to set defaults in .env (all environments),
.env.development (development environment), and .env.production
(production environment).
.env.local always overrides the defaults set.
Here You have much more examples how to use .env properly in next.js. source, source
Good Luck and enjoy your study ;-)!
Related
I'm searching of 'env' concept at static build file in Next.js but can't understand what is "inlining" meaning in this context. Could someone give me more specific example?
This loads process.env.NEXT_PUBLIC_ANALYTICS_ID into the Node.js environment automatically, allowing you to use it anywhere in your code. The value will be inlined into JavaScript sent to the browser because of the NEXT_PUBLIC_ prefix. This inlining occurs at build time, so your various NEXT_PUBLIC_ envs need to be set when the project is built.
https://nextjs.org/docs/basic-features/environment-variables#exposing-environment-variables-to-the-browser
It means that when the build tool generates the source code to send to the browser, it will replace the instruction to read an an environment variable with a string representing the value of that environment variable at the time the build happened.
I am using the Symfony profiler. But I actually only want to make it visible in the Dev mode. But when I push the data via git on my server and open the website, I see the profiler. That does not make sense of cause, but I do not know how to remove it.
I was looking for the file called config/config_dev.yml and config/config.yml because I would think that in config/config.yml I should just set to:
web_profiler:
toolbar: false
intercept_redirects: false
But I do not have any config.yml files. Do I have to create them?
On your server, copy your .env.dist (if you have one) to .env, and set APP_ENV=prod
If you don't yet have a .env file, create one at the root of you project, and put APP_ENV=prod in it.
That being said, note that best practice is to use server level configuration in production env. Reference link : https://symfony.com/doc/current/configuration/external_parameters.html#configuring-environment-variables-in-production
EDIT (based on the comments) for your information :
.env is a file where you will mainly put your global configuration. The .dist variant is meant to be added to git, it won't be used by symfony but is useful for the developpers (including you) to have a default config file to rely on.
Basically, when they'll pull the project for the first time, they'll copy this file to .env then adjust the lines/config to their liking.
The .env must not be added to git for it will be the file that will be used by symfony. If you add it to git, each time you will push your local work then pull from your server, it will replace your server configuration with your local one.
I want to create a file called config.js for the client end of my app, but it should be based on the environment. I've successfully done this for production using the tasks/register/prod.js file, but sailsjs does not seem to have an equivalent dev.js file.
I also can't find much information about this, so I'm hoping there is a standard workaround I'm just not thinking of.
I'm not sure why I found it so confusing, or why I never opened the README.md (duh!) in tasks/, but dev stuff goes in the default task (tasks/register/default.js).
ANSWER: README's are named as such for a very good reason.
I used to write my configs for Symfony project like this in config.yml file:
my_bundle:
internal_identifier: %test%
key: %someparam%
endpoint: %nobil_endpoint%
and used parameters.yml (which was ignored by git) for allowing other developers to have different values.
Bu I think using this:
my_bundle:
internal_identifier: my-identifier
key: 12345
endpoint: www.endpoint.com
still allows developers to have different values because they can use config_dev.yml which is also ignored by Git.
So my question is this: what's the purpose of parameters.yml file if config_dev.yml can be used for the same thing?
I think two things are being asked here:
Why is parameters.yml ignored be the default Symfony .gitignore file?
Why use parameters.yml instead of config_dev.yml?
Per the first question, parameters.yml is ignored by default because this file is meant to hold settings which are per-installation. For instance different developers might need different database settings. If parameters.yml wasn't ignored, your "personal" settings would be copied to every developer.
As of Symfony 2.3 you should put the needed parameters, along with default values, in a file called parameters.yml.dist. Then, when you run composer install a composer script will check for this file and create/update your local parameters.yml file, prompting you for each setting which gives you the opportunity to change the settings to be relevant to the given install.
Per the second issue, parameters are considered different than config settings. Parameters are settings which will change install to install, whereas config settings will stay the same for all installs of a particular app (although they may be different from dev to production environments.)
first, what is ignored by git is up to you, there is a .gitignore file in your repo-root
my advice to use different parameters would be:
you have different parameter.yml´s like :
parameters.yml.dev.one
parameters.yml.dev.two
parameters.yml.dev.three
and for example you are developer one then you make a symbolic link to "your" parameters.yml.dev.one like :
cd app/config; ln -s parameters.yml.dev.one parameters.yml
so now there is a parameters.yml on your machine that points on your parameters
developer two would make a symbolic link to his parameters and so on
if you are not clear about the difference between parameters and config, please check symfony book
you can do the same with your stages when you need for example another database-connection on prelive or live or whatever by using symbolic links
the advantage of this is that every developer has the parameters of every stage and developer on his machine
cheers
Being ignored by Git is the most useful, but it also prompts you for missing values when doing composer install.
If you want to have common parameters that are not ignored, you can create a parameters_common.yml and source it in config.yml (or add them directly in config.yml).
For an advanced use of config/parameters files, I suggest you check https://github.com/wemakecustom/DirectoryLoaderBundle
Because where you are in production environment, symfony needs to work in PRODuction environment and not in DEV.
Why you removed config_dev.yml from repository?
in my project, I want to refer to an other xcconfig file, located in InDesign SDK. As this SDK may be installed at different locations, depending upon the machine, I prefer to declare an environment variable for locating it.
Nest step is obviously to use variable (aptly named ID_CS5_SDK_DIR) in my xcconfig include directive.
Unfortunatly, when I try the simple
// InDesign sdk project build settings (based on common build settings)
#include "$(ID_CS5_SDK_ROOT)/build/mac/prj/_shared_build_settings/common.xcconfig"
XCode throws me a
[WARN]AutocatPlugin.xcconfig line 7: Unable to find included file "$(ID_CS5_SDK_ROOT)/build/mac/prj/_shared_build_settings/common.xcconfig"
How can I make it work ?
I've been trying to do this too and also came to the conclusion that it is not possible.
I once tried to achieve that and came to the conclusion that you can't. I would be happy if someone proves us it's possible though then delete my answer
It seems like .xcconfig files can only DEFINE and set value to environment variables (which prevail only throughout the build session) but not USE or evaluate environment variables.
Maybe it is because .xcconfig files serve as a base layer of build-settings, and are not parsed.
Unfortunately this is not possible, but instead of making one include the other, you can use two different xcconfig files per target. Just select one for the Project and one for the Target.
If you put the environment variable in /etc/config/launchd.conf and then reboot it will be accessible to the .xcconfig file.
Short Instructions for experienced users:
Edit the read-only file /etc/launchd.conf and add 'setenv VARIABLENAME /FOLDER/PATH' to the file, then reboot.
Steps For Inexperienced Users
Open Application/Utilities/Terminal, and entersudo nano /etc/launchd.conf
Create the Environment Variable by adding a line like setenv VARIABLENAME FOLDER/PATH and then pressing ENTER.
Save the file using Ctrl-O, Ctrl-M, (Possibly Ctrl-Y to overwrite), then Ctrl-X to exit the editor.
(Optional) type cat /etc/launchd.conf to see that your changes are present
Restart your computer. (Logoff doesn't work)
You can now access the variable in your .xcconfig file as$(VARIABLENAME)
Notes:
This creates a GLOBAL environment variable, accessible to all users. It probably doesn't make sense to set this to something in your home directory (e.g ~/MyFolder). If you do this, however, you need to use the full pathname, such as /Users/MyUserName/MyFolder).
References:
Stack Overflow - Setting Environment Variables in OSX
Stack Overflow - Are there any differences between /etc and /private /etc