I'm building my function with webpack that get deployed to AWS lambda.
I currently have to specify the environment variable at compile time for them to be available as per webpack doc.
This is awesome for web deployment, but for node I might want to change the values passed at build, by changing the env file i'm sourcing from. For example .env.staging or .env.production without having to rebuild the application or directly on my lambda environment.
How can I achieve this if possible? I'm using webpack4
Related
I am using Nuxt3 and Prisma to build the application, in the development environment, they run fine, when I execute the npm run buildcommand, there is also no output error.nuxt3 outputs the .output folder.
build
But when I use the command start to run, prisma prompts me environment variable could not be found.
error
I recreated the .env file under the output .prisma folder, but it doesn't work.
recreated
How can I solve the environment variable in production problem?
Your .env file should be in the same directory as your schema.prisma file. I'm not sure what framework/library you are using, but it looks like it emits a schema.prisma file within node_modules, which is not where your environment variables should go. Wherever you actually have your schema.prisma is where the .env file should go.
Take a look at the Prisma documentation about environment variables if you need help configuring where it's supposed to go: https://www.prisma.io/docs/guides/development-environment/environment-variables
I have a nodejs project which is using nodemon for providing environment variables when running locally. I have a need to have the developers easily switch between two different nodemon config files (two different sets of environment variables). But I can't see a way to specify a config file for nodemon. How can I accomplish this.
You can specify the config file using the --config flag:
https://github.com/remy/nodemon#config-files
I have a Gatsby project with a couple functions. I'd like to migrate some of my variables to env variables. Setting these up in Netlify is a breeze.
However, locally I'm trying to test my functions using netlify dev. It starts up fine, but as soon as I hit my endpoint, there are issues because I'm accessing non-existent properties on process.env. I have tried adding a .env and .env.development file in the root of my project (where I run netlify dev) but it doesn't seem to be reading them. The documentation I've ready only mentions netlify.toml files, but the whole point is to not have it in source control.
Is there something I need to do for the command to pick up my .env file?
Configure your build to grab your .env and copy it over to the location that is used to deploy the website.
An example would be to add the copy step to your build command:
// netlify.toml
[build]
command = "do-build && cp .env functions/"
Although this will only work for local deploys with the netlify command. If you want to do it with their automated deploys, there is no way around checking in the .env file.
To avoid that, you are expected to set those values through the project UI in Netlify's website.
You can create environment variables in the toml file or in our UI. You might use the latter to keep sensitive values out of your repository.
https://docs.netlify.com/configure-builds/file-based-configuration/#inject-environment-variable-values
I deployed a little web app to Netlify and noticed my bundle.js file is only 157kb. When I run a production build locally, it's 575kb. I'm not mad about it, but how is Netlify doing that?
The app is using browserify to bundle my scripts as well as babel and uglify. browserify script.js | uglifyjs > dist/bundle.js That's the same script I told Netlify to run in the settings.
I think it must be some kind of default setting on Netlify builds?
I thought it might be my NODE_ENV environment variable was set to development, but I double checked and it's set to production. I even tried adding set NODE_ENV=production && before my build script just to make sure.
Is Netlify magic? What else could be different between my local setup and Netlify?
Maybe gzip?
Read more about it here: https://www.gzip.org/
See if there's a header called Content-Encoding: gzip and you'll know for sure.
i have an angular project. I want to build the project to be different depending on whether the process.env.NODE_ENV file is test or production.
Angular has a ng build command that you can tag with configuration to define whether the project should be built as "test" or "production". Instead of hard coding these values i want it to be based on the process.env variable.
How do i access this process.env.NODE_ENV variable within my package.json script command.
npm run build
"build": "ng build --configuration=process.env.NODE_ENV",
At the moment i get the following error
Configuration 'NODE_ENV' could not be found in project 'demo'. Error:
Configuration 'NODE_ENV' could not be found in project 'demo'.
NODE_ENV=prod npm run build
This will set the environment variable in process.env so you can access anywhere in node.js script.
This way you can pass any value into NODE_ENV while running.
ng build --configuration=$NODE_ENV
or
ng build --configuration=%NODE_ENV%
depending on your platform.
process.env is only accessible through a javascript file running on node.js, what you need here is to use the shell syntax