Set environment variable for build in NetlifyWhere to put secret keys in Netlify?Is it possible to set access_token in netlify.toml file?Setting environment variables after webpack buildExpose API routes with Express when deployed on NetlifyDrafts rendered by netlify when draft: true in yaml“Page Not Found” when trying to access a site deployed on NetlifyIssue getting .env to work on Netlify. Nuxt Netlify .envSetting Up A Staging Workflow With Netlify CMSHow do I deploy Vue Webpack-simple app to Netlify?I can not access my environment variables in netlifygatsby-config for production ENV variable“Successful” Netlify Form Submissions Don't Show in Dashboard

Why are two-stroke engines nearly unheard of in aviation?

Why is the return value of the fun function 8 instead of 7?

Why 1.5fill is 0pt

Can Brexit be undone in an emergency?

Are articles good enough to be the main source of information for PhD research?

Did slaves have slaves?

Why does dd not make working bootable USB sticks for Microsoft?

Why is belonging not transitive?

Why is the UK still pressing on with Brexit?

Is my sink P-trap too low?

Amortized Loans seem to benefit the bank more than the customer

Is there a generally agreed upon solution to Bradley's Infinite Regress without appeal to Paraconsistent Logic?

Where is it? - The Google Earth Challenge Ep. 4

Why don't airports use arresting gears to recover energy from landing passenger planes?

Should I inform my future product owner that there are big chances that a team member will leave the company soon?

Hobby function generators

How would you control supersoldiers in a late iron-age society?

Very lazy puppy

Does Forgotten Realms setting count as “High magic”?

Answer Not A Fool, or Answer A Fool?

What is this WWII four-engine plane on skis?

Why does an orbit become hyperbolic when total orbital energy is positive?

What are the typical trumpet parts in classical music?

Bit one of the Intel 8080's Flags register



Set environment variable for build in Netlify


Where to put secret keys in Netlify?Is it possible to set access_token in netlify.toml file?Setting environment variables after webpack buildExpose API routes with Express when deployed on NetlifyDrafts rendered by netlify when draft: true in yaml“Page Not Found” when trying to access a site deployed on NetlifyIssue getting .env to work on Netlify. Nuxt Netlify .envSetting Up A Staging Workflow With Netlify CMSHow do I deploy Vue Webpack-simple app to Netlify?I can not access my environment variables in netlifygatsby-config for production ENV variable“Successful” Netlify Form Submissions Don't Show in Dashboard






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








7















I'm trying to set an environment variable for an API key that I don't want in my code. My source javascript looks something like this :



.get(`http://api-url-and-parameters&api-key=$process.env.API_KEY`)


I'm using webpack and the package dotenv-webpack https://www.npmjs.com/package/dotenv-webpack to set API_KEY in a gitignored .env file and it's all running fine on my local. I'd like to also be able to set that variable when deploying through Netlify, I've tried adding it through to GUI to the 'build environment variables', and also to set it directly in the build command, but without success.



Any idea what might be the issue ?










share|improve this question



















  • 1





    just to be clear - you are running that JS at build time with webpack, not intending it to do something at browse-time, right?

    – fool
    Jan 26 '18 at 15:14











  • Yes I should have clarified but as the title suggests this is only called at build time and not exposed anywhere at run time.

    – Maëlig
    Apr 5 at 6:59

















7















I'm trying to set an environment variable for an API key that I don't want in my code. My source javascript looks something like this :



.get(`http://api-url-and-parameters&api-key=$process.env.API_KEY`)


I'm using webpack and the package dotenv-webpack https://www.npmjs.com/package/dotenv-webpack to set API_KEY in a gitignored .env file and it's all running fine on my local. I'd like to also be able to set that variable when deploying through Netlify, I've tried adding it through to GUI to the 'build environment variables', and also to set it directly in the build command, but without success.



Any idea what might be the issue ?










share|improve this question



















  • 1





    just to be clear - you are running that JS at build time with webpack, not intending it to do something at browse-time, right?

    – fool
    Jan 26 '18 at 15:14











  • Yes I should have clarified but as the title suggests this is only called at build time and not exposed anywhere at run time.

    – Maëlig
    Apr 5 at 6:59













7












7








7


3






I'm trying to set an environment variable for an API key that I don't want in my code. My source javascript looks something like this :



.get(`http://api-url-and-parameters&api-key=$process.env.API_KEY`)


I'm using webpack and the package dotenv-webpack https://www.npmjs.com/package/dotenv-webpack to set API_KEY in a gitignored .env file and it's all running fine on my local. I'd like to also be able to set that variable when deploying through Netlify, I've tried adding it through to GUI to the 'build environment variables', and also to set it directly in the build command, but without success.



Any idea what might be the issue ?










share|improve this question














I'm trying to set an environment variable for an API key that I don't want in my code. My source javascript looks something like this :



.get(`http://api-url-and-parameters&api-key=$process.env.API_KEY`)


I'm using webpack and the package dotenv-webpack https://www.npmjs.com/package/dotenv-webpack to set API_KEY in a gitignored .env file and it's all running fine on my local. I'd like to also be able to set that variable when deploying through Netlify, I've tried adding it through to GUI to the 'build environment variables', and also to set it directly in the build command, but without success.



Any idea what might be the issue ?







webpack netlify






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 25 '18 at 23:20









MaëligMaëlig

991 silver badge7 bronze badges




991 silver badge7 bronze badges










  • 1





    just to be clear - you are running that JS at build time with webpack, not intending it to do something at browse-time, right?

    – fool
    Jan 26 '18 at 15:14











  • Yes I should have clarified but as the title suggests this is only called at build time and not exposed anywhere at run time.

    – Maëlig
    Apr 5 at 6:59












  • 1





    just to be clear - you are running that JS at build time with webpack, not intending it to do something at browse-time, right?

    – fool
    Jan 26 '18 at 15:14











  • Yes I should have clarified but as the title suggests this is only called at build time and not exposed anywhere at run time.

    – Maëlig
    Apr 5 at 6:59







1




1





just to be clear - you are running that JS at build time with webpack, not intending it to do something at browse-time, right?

– fool
Jan 26 '18 at 15:14





just to be clear - you are running that JS at build time with webpack, not intending it to do something at browse-time, right?

– fool
Jan 26 '18 at 15:14













Yes I should have clarified but as the title suggests this is only called at build time and not exposed anywhere at run time.

– Maëlig
Apr 5 at 6:59





Yes I should have clarified but as the title suggests this is only called at build time and not exposed anywhere at run time.

– Maëlig
Apr 5 at 6:59












4 Answers
4






active

oldest

votes


















12
















WARNING: If this is a secret key, you will not want to expose this environment variable value in any bundle that gets returned to the client. It should only be used by your build scripts to be used to create your content during build.



Issue



dotenv-webpack expects there to be a .env file to load in your variables during the webpack build of your bundle. When the repository is checked out by Netlify, the .env does not exist because for good reason it is in .gitignore.



Solution



Store your API_KEY in the Netlify build environment variables and build the .env using a script prior to running the build command.



scripts/create-env.js



const fs = require('fs')
fs.writeFileSync('./.env', `API_KEY=$process.env.API_KEYn`)


Run the script as part of your build



node ./scripts/create-env.js && <your_existing_webpack_build_command>



Caveats & Recommendations




  • Do not use this method with a public facing repository [open] because any PR or branch deploy could create a simple script into your code to expose the API_KEY

  • The example script above is for simplicity so, make any script you use be able to error out with a code other than 0 so if the script fails the deploy will fail.





share|improve this answer




















  • 2





    this is a great answer, totally endorsed by the team at Netlify support! That "Build Environment Variables" section is on your Build & Deploy settings page - second "card" down

    – fool
    Jan 27 '18 at 1:31












  • Thanks, that worked like a charm. I was halfway there but didn't realise you could create files on the fly using Netlify.

    – Maëlig
    Jan 29 '18 at 18:48











  • I found this solution after a lot of Googling and it works for me but it's weird there's no official documentation for this on Netlify @fool

    – Dan
    Dec 13 '18 at 14:02







  • 1





    @DanChristian Probably, the reason you don't see this in official docs is this would not fit a general solution rule for environment variables, because there are many build solutions supported by Netlify. My solution really just solves IF your project requires a .env setup, but does help if you want to use it as an alternative. Environment variables are typically accessible at build time.

    – talves
    Dec 13 '18 at 17:44











  • @JBalin the OP is not using the keys in his front end code from what he says.The OP even states it in the comments when asked. Only during his build process. I agree with you that he should not be using thees keys in client code.

    – talves
    Apr 5 at 13:54



















4
















You can set Dotenv-webpack to load system environment variables as well as those you have declared in your .env file by doing the following:



 plugins: [
new Dotenv(
systemvars: true
)
]


I.e Setting the systemvars attribute of your webpack dotenv plugin to true.



Note that system environment variables with the same name will overwrite those defined in your .env file.



Source: https://www.npmjs.com/package/dotenv-webpack#properties






share|improve this answer
































    2
















    if you go to corresponding site's settings in Netlify, under build&deploy you can find a section called environment variables you can easily add your environment variables from there. if you add MY_API_KEY variable to environment variables you will be able to access it inside your project via process.env.MY_API_KEY.



    enter image description here






    share|improve this answer
































      1
















      If you're using Nuxt JS there is a more "straight forward" approach.



      Just edit the nuxt.config.js like so:



      module.exports = {
      env:
      GOOGLE_API_KEY: process.env.GOOGLE_API_KEY

      ,
      // ...


      Then add the GOOGLE_API_KEY to Netlify through the build environment variables as usual.



      Credit goes to yann-linn and his answer on github.






      share|improve this answer



























        Your Answer






        StackExchange.ifUsing("editor", function ()
        StackExchange.using("externalEditor", function ()
        StackExchange.using("snippets", function ()
        StackExchange.snippets.init();
        );
        );
        , "code-snippets");

        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "1"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );














        draft saved

        draft discarded
















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48453493%2fset-environment-variable-for-build-in-netlify%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        12
















        WARNING: If this is a secret key, you will not want to expose this environment variable value in any bundle that gets returned to the client. It should only be used by your build scripts to be used to create your content during build.



        Issue



        dotenv-webpack expects there to be a .env file to load in your variables during the webpack build of your bundle. When the repository is checked out by Netlify, the .env does not exist because for good reason it is in .gitignore.



        Solution



        Store your API_KEY in the Netlify build environment variables and build the .env using a script prior to running the build command.



        scripts/create-env.js



        const fs = require('fs')
        fs.writeFileSync('./.env', `API_KEY=$process.env.API_KEYn`)


        Run the script as part of your build



        node ./scripts/create-env.js && <your_existing_webpack_build_command>



        Caveats & Recommendations




        • Do not use this method with a public facing repository [open] because any PR or branch deploy could create a simple script into your code to expose the API_KEY

        • The example script above is for simplicity so, make any script you use be able to error out with a code other than 0 so if the script fails the deploy will fail.





        share|improve this answer




















        • 2





          this is a great answer, totally endorsed by the team at Netlify support! That "Build Environment Variables" section is on your Build & Deploy settings page - second "card" down

          – fool
          Jan 27 '18 at 1:31












        • Thanks, that worked like a charm. I was halfway there but didn't realise you could create files on the fly using Netlify.

          – Maëlig
          Jan 29 '18 at 18:48











        • I found this solution after a lot of Googling and it works for me but it's weird there's no official documentation for this on Netlify @fool

          – Dan
          Dec 13 '18 at 14:02







        • 1





          @DanChristian Probably, the reason you don't see this in official docs is this would not fit a general solution rule for environment variables, because there are many build solutions supported by Netlify. My solution really just solves IF your project requires a .env setup, but does help if you want to use it as an alternative. Environment variables are typically accessible at build time.

          – talves
          Dec 13 '18 at 17:44











        • @JBalin the OP is not using the keys in his front end code from what he says.The OP even states it in the comments when asked. Only during his build process. I agree with you that he should not be using thees keys in client code.

          – talves
          Apr 5 at 13:54
















        12
















        WARNING: If this is a secret key, you will not want to expose this environment variable value in any bundle that gets returned to the client. It should only be used by your build scripts to be used to create your content during build.



        Issue



        dotenv-webpack expects there to be a .env file to load in your variables during the webpack build of your bundle. When the repository is checked out by Netlify, the .env does not exist because for good reason it is in .gitignore.



        Solution



        Store your API_KEY in the Netlify build environment variables and build the .env using a script prior to running the build command.



        scripts/create-env.js



        const fs = require('fs')
        fs.writeFileSync('./.env', `API_KEY=$process.env.API_KEYn`)


        Run the script as part of your build



        node ./scripts/create-env.js && <your_existing_webpack_build_command>



        Caveats & Recommendations




        • Do not use this method with a public facing repository [open] because any PR or branch deploy could create a simple script into your code to expose the API_KEY

        • The example script above is for simplicity so, make any script you use be able to error out with a code other than 0 so if the script fails the deploy will fail.





        share|improve this answer




















        • 2





          this is a great answer, totally endorsed by the team at Netlify support! That "Build Environment Variables" section is on your Build & Deploy settings page - second "card" down

          – fool
          Jan 27 '18 at 1:31












        • Thanks, that worked like a charm. I was halfway there but didn't realise you could create files on the fly using Netlify.

          – Maëlig
          Jan 29 '18 at 18:48











        • I found this solution after a lot of Googling and it works for me but it's weird there's no official documentation for this on Netlify @fool

          – Dan
          Dec 13 '18 at 14:02







        • 1





          @DanChristian Probably, the reason you don't see this in official docs is this would not fit a general solution rule for environment variables, because there are many build solutions supported by Netlify. My solution really just solves IF your project requires a .env setup, but does help if you want to use it as an alternative. Environment variables are typically accessible at build time.

          – talves
          Dec 13 '18 at 17:44











        • @JBalin the OP is not using the keys in his front end code from what he says.The OP even states it in the comments when asked. Only during his build process. I agree with you that he should not be using thees keys in client code.

          – talves
          Apr 5 at 13:54














        12














        12










        12









        WARNING: If this is a secret key, you will not want to expose this environment variable value in any bundle that gets returned to the client. It should only be used by your build scripts to be used to create your content during build.



        Issue



        dotenv-webpack expects there to be a .env file to load in your variables during the webpack build of your bundle. When the repository is checked out by Netlify, the .env does not exist because for good reason it is in .gitignore.



        Solution



        Store your API_KEY in the Netlify build environment variables and build the .env using a script prior to running the build command.



        scripts/create-env.js



        const fs = require('fs')
        fs.writeFileSync('./.env', `API_KEY=$process.env.API_KEYn`)


        Run the script as part of your build



        node ./scripts/create-env.js && <your_existing_webpack_build_command>



        Caveats & Recommendations




        • Do not use this method with a public facing repository [open] because any PR or branch deploy could create a simple script into your code to expose the API_KEY

        • The example script above is for simplicity so, make any script you use be able to error out with a code other than 0 so if the script fails the deploy will fail.





        share|improve this answer













        WARNING: If this is a secret key, you will not want to expose this environment variable value in any bundle that gets returned to the client. It should only be used by your build scripts to be used to create your content during build.



        Issue



        dotenv-webpack expects there to be a .env file to load in your variables during the webpack build of your bundle. When the repository is checked out by Netlify, the .env does not exist because for good reason it is in .gitignore.



        Solution



        Store your API_KEY in the Netlify build environment variables and build the .env using a script prior to running the build command.



        scripts/create-env.js



        const fs = require('fs')
        fs.writeFileSync('./.env', `API_KEY=$process.env.API_KEYn`)


        Run the script as part of your build



        node ./scripts/create-env.js && <your_existing_webpack_build_command>



        Caveats & Recommendations




        • Do not use this method with a public facing repository [open] because any PR or branch deploy could create a simple script into your code to expose the API_KEY

        • The example script above is for simplicity so, make any script you use be able to error out with a code other than 0 so if the script fails the deploy will fail.






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 26 '18 at 17:38









        talvestalves

        7,5092 gold badges20 silver badges43 bronze badges




        7,5092 gold badges20 silver badges43 bronze badges










        • 2





          this is a great answer, totally endorsed by the team at Netlify support! That "Build Environment Variables" section is on your Build & Deploy settings page - second "card" down

          – fool
          Jan 27 '18 at 1:31












        • Thanks, that worked like a charm. I was halfway there but didn't realise you could create files on the fly using Netlify.

          – Maëlig
          Jan 29 '18 at 18:48











        • I found this solution after a lot of Googling and it works for me but it's weird there's no official documentation for this on Netlify @fool

          – Dan
          Dec 13 '18 at 14:02







        • 1





          @DanChristian Probably, the reason you don't see this in official docs is this would not fit a general solution rule for environment variables, because there are many build solutions supported by Netlify. My solution really just solves IF your project requires a .env setup, but does help if you want to use it as an alternative. Environment variables are typically accessible at build time.

          – talves
          Dec 13 '18 at 17:44











        • @JBalin the OP is not using the keys in his front end code from what he says.The OP even states it in the comments when asked. Only during his build process. I agree with you that he should not be using thees keys in client code.

          – talves
          Apr 5 at 13:54













        • 2





          this is a great answer, totally endorsed by the team at Netlify support! That "Build Environment Variables" section is on your Build & Deploy settings page - second "card" down

          – fool
          Jan 27 '18 at 1:31












        • Thanks, that worked like a charm. I was halfway there but didn't realise you could create files on the fly using Netlify.

          – Maëlig
          Jan 29 '18 at 18:48











        • I found this solution after a lot of Googling and it works for me but it's weird there's no official documentation for this on Netlify @fool

          – Dan
          Dec 13 '18 at 14:02







        • 1





          @DanChristian Probably, the reason you don't see this in official docs is this would not fit a general solution rule for environment variables, because there are many build solutions supported by Netlify. My solution really just solves IF your project requires a .env setup, but does help if you want to use it as an alternative. Environment variables are typically accessible at build time.

          – talves
          Dec 13 '18 at 17:44











        • @JBalin the OP is not using the keys in his front end code from what he says.The OP even states it in the comments when asked. Only during his build process. I agree with you that he should not be using thees keys in client code.

          – talves
          Apr 5 at 13:54








        2




        2





        this is a great answer, totally endorsed by the team at Netlify support! That "Build Environment Variables" section is on your Build & Deploy settings page - second "card" down

        – fool
        Jan 27 '18 at 1:31






        this is a great answer, totally endorsed by the team at Netlify support! That "Build Environment Variables" section is on your Build & Deploy settings page - second "card" down

        – fool
        Jan 27 '18 at 1:31














        Thanks, that worked like a charm. I was halfway there but didn't realise you could create files on the fly using Netlify.

        – Maëlig
        Jan 29 '18 at 18:48





        Thanks, that worked like a charm. I was halfway there but didn't realise you could create files on the fly using Netlify.

        – Maëlig
        Jan 29 '18 at 18:48













        I found this solution after a lot of Googling and it works for me but it's weird there's no official documentation for this on Netlify @fool

        – Dan
        Dec 13 '18 at 14:02






        I found this solution after a lot of Googling and it works for me but it's weird there's no official documentation for this on Netlify @fool

        – Dan
        Dec 13 '18 at 14:02





        1




        1





        @DanChristian Probably, the reason you don't see this in official docs is this would not fit a general solution rule for environment variables, because there are many build solutions supported by Netlify. My solution really just solves IF your project requires a .env setup, but does help if you want to use it as an alternative. Environment variables are typically accessible at build time.

        – talves
        Dec 13 '18 at 17:44





        @DanChristian Probably, the reason you don't see this in official docs is this would not fit a general solution rule for environment variables, because there are many build solutions supported by Netlify. My solution really just solves IF your project requires a .env setup, but does help if you want to use it as an alternative. Environment variables are typically accessible at build time.

        – talves
        Dec 13 '18 at 17:44













        @JBalin the OP is not using the keys in his front end code from what he says.The OP even states it in the comments when asked. Only during his build process. I agree with you that he should not be using thees keys in client code.

        – talves
        Apr 5 at 13:54






        @JBalin the OP is not using the keys in his front end code from what he says.The OP even states it in the comments when asked. Only during his build process. I agree with you that he should not be using thees keys in client code.

        – talves
        Apr 5 at 13:54














        4
















        You can set Dotenv-webpack to load system environment variables as well as those you have declared in your .env file by doing the following:



         plugins: [
        new Dotenv(
        systemvars: true
        )
        ]


        I.e Setting the systemvars attribute of your webpack dotenv plugin to true.



        Note that system environment variables with the same name will overwrite those defined in your .env file.



        Source: https://www.npmjs.com/package/dotenv-webpack#properties






        share|improve this answer





























          4
















          You can set Dotenv-webpack to load system environment variables as well as those you have declared in your .env file by doing the following:



           plugins: [
          new Dotenv(
          systemvars: true
          )
          ]


          I.e Setting the systemvars attribute of your webpack dotenv plugin to true.



          Note that system environment variables with the same name will overwrite those defined in your .env file.



          Source: https://www.npmjs.com/package/dotenv-webpack#properties






          share|improve this answer



























            4














            4










            4









            You can set Dotenv-webpack to load system environment variables as well as those you have declared in your .env file by doing the following:



             plugins: [
            new Dotenv(
            systemvars: true
            )
            ]


            I.e Setting the systemvars attribute of your webpack dotenv plugin to true.



            Note that system environment variables with the same name will overwrite those defined in your .env file.



            Source: https://www.npmjs.com/package/dotenv-webpack#properties






            share|improve this answer













            You can set Dotenv-webpack to load system environment variables as well as those you have declared in your .env file by doing the following:



             plugins: [
            new Dotenv(
            systemvars: true
            )
            ]


            I.e Setting the systemvars attribute of your webpack dotenv plugin to true.



            Note that system environment variables with the same name will overwrite those defined in your .env file.



            Source: https://www.npmjs.com/package/dotenv-webpack#properties







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jun 2 '18 at 12:06









            Riky_TreeRiky_Tree

            1412 silver badges5 bronze badges




            1412 silver badges5 bronze badges
























                2
















                if you go to corresponding site's settings in Netlify, under build&deploy you can find a section called environment variables you can easily add your environment variables from there. if you add MY_API_KEY variable to environment variables you will be able to access it inside your project via process.env.MY_API_KEY.



                enter image description here






                share|improve this answer





























                  2
















                  if you go to corresponding site's settings in Netlify, under build&deploy you can find a section called environment variables you can easily add your environment variables from there. if you add MY_API_KEY variable to environment variables you will be able to access it inside your project via process.env.MY_API_KEY.



                  enter image description here






                  share|improve this answer



























                    2














                    2










                    2









                    if you go to corresponding site's settings in Netlify, under build&deploy you can find a section called environment variables you can easily add your environment variables from there. if you add MY_API_KEY variable to environment variables you will be able to access it inside your project via process.env.MY_API_KEY.



                    enter image description here






                    share|improve this answer













                    if you go to corresponding site's settings in Netlify, under build&deploy you can find a section called environment variables you can easily add your environment variables from there. if you add MY_API_KEY variable to environment variables you will be able to access it inside your project via process.env.MY_API_KEY.



                    enter image description here







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Apr 20 at 17:58









                    Lakshan SLakshan S

                    6687 silver badges13 bronze badges




                    6687 silver badges13 bronze badges
























                        1
















                        If you're using Nuxt JS there is a more "straight forward" approach.



                        Just edit the nuxt.config.js like so:



                        module.exports = {
                        env:
                        GOOGLE_API_KEY: process.env.GOOGLE_API_KEY

                        ,
                        // ...


                        Then add the GOOGLE_API_KEY to Netlify through the build environment variables as usual.



                        Credit goes to yann-linn and his answer on github.






                        share|improve this answer





























                          1
















                          If you're using Nuxt JS there is a more "straight forward" approach.



                          Just edit the nuxt.config.js like so:



                          module.exports = {
                          env:
                          GOOGLE_API_KEY: process.env.GOOGLE_API_KEY

                          ,
                          // ...


                          Then add the GOOGLE_API_KEY to Netlify through the build environment variables as usual.



                          Credit goes to yann-linn and his answer on github.






                          share|improve this answer



























                            1














                            1










                            1









                            If you're using Nuxt JS there is a more "straight forward" approach.



                            Just edit the nuxt.config.js like so:



                            module.exports = {
                            env:
                            GOOGLE_API_KEY: process.env.GOOGLE_API_KEY

                            ,
                            // ...


                            Then add the GOOGLE_API_KEY to Netlify through the build environment variables as usual.



                            Credit goes to yann-linn and his answer on github.






                            share|improve this answer













                            If you're using Nuxt JS there is a more "straight forward" approach.



                            Just edit the nuxt.config.js like so:



                            module.exports = {
                            env:
                            GOOGLE_API_KEY: process.env.GOOGLE_API_KEY

                            ,
                            // ...


                            Then add the GOOGLE_API_KEY to Netlify through the build environment variables as usual.



                            Credit goes to yann-linn and his answer on github.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 13 at 10:40









                            Peter PiperPeter Piper

                            1,6701 gold badge21 silver badges37 bronze badges




                            1,6701 gold badge21 silver badges37 bronze badges































                                draft saved

                                draft discarded















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48453493%2fset-environment-variable-for-build-in-netlify%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                                Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                                Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript