Dotenv not loading properly












4















I am trying to access some environment variables using process.env that were loaded by dotenv.



My folder structure :



.env
src
-- - server.js


My server.js configuration :



(...)
import auth from './middleware/auth'
import dotenv from 'dotenv'
dotenv.load({
path: '../',
silent: process.env.NODE_ENV === 'production'
})
auth()
// Instantiate app
const app = express();


The file where I try to access process.env variable :



(...)
module.exports = function() {
console.log("env", process.env.MONGODB_URI)
var options = {};
options.jwtFromRequest = ExtractJwt.fromAuthHeader()
options.secretOrKey = process.env.JWT_SECRET


Which logs env, undefined, and then crashes with



TypeError: JwtStrategy requires a secret or key



Even if I move .env into src (same directory as server) and remove path in config, it fails.










share|improve this question





























    4















    I am trying to access some environment variables using process.env that were loaded by dotenv.



    My folder structure :



    .env
    src
    -- - server.js


    My server.js configuration :



    (...)
    import auth from './middleware/auth'
    import dotenv from 'dotenv'
    dotenv.load({
    path: '../',
    silent: process.env.NODE_ENV === 'production'
    })
    auth()
    // Instantiate app
    const app = express();


    The file where I try to access process.env variable :



    (...)
    module.exports = function() {
    console.log("env", process.env.MONGODB_URI)
    var options = {};
    options.jwtFromRequest = ExtractJwt.fromAuthHeader()
    options.secretOrKey = process.env.JWT_SECRET


    Which logs env, undefined, and then crashes with



    TypeError: JwtStrategy requires a secret or key



    Even if I move .env into src (same directory as server) and remove path in config, it fails.










    share|improve this question



























      4












      4








      4








      I am trying to access some environment variables using process.env that were loaded by dotenv.



      My folder structure :



      .env
      src
      -- - server.js


      My server.js configuration :



      (...)
      import auth from './middleware/auth'
      import dotenv from 'dotenv'
      dotenv.load({
      path: '../',
      silent: process.env.NODE_ENV === 'production'
      })
      auth()
      // Instantiate app
      const app = express();


      The file where I try to access process.env variable :



      (...)
      module.exports = function() {
      console.log("env", process.env.MONGODB_URI)
      var options = {};
      options.jwtFromRequest = ExtractJwt.fromAuthHeader()
      options.secretOrKey = process.env.JWT_SECRET


      Which logs env, undefined, and then crashes with



      TypeError: JwtStrategy requires a secret or key



      Even if I move .env into src (same directory as server) and remove path in config, it fails.










      share|improve this question
















      I am trying to access some environment variables using process.env that were loaded by dotenv.



      My folder structure :



      .env
      src
      -- - server.js


      My server.js configuration :



      (...)
      import auth from './middleware/auth'
      import dotenv from 'dotenv'
      dotenv.load({
      path: '../',
      silent: process.env.NODE_ENV === 'production'
      })
      auth()
      // Instantiate app
      const app = express();


      The file where I try to access process.env variable :



      (...)
      module.exports = function() {
      console.log("env", process.env.MONGODB_URI)
      var options = {};
      options.jwtFromRequest = ExtractJwt.fromAuthHeader()
      options.secretOrKey = process.env.JWT_SECRET


      Which logs env, undefined, and then crashes with



      TypeError: JwtStrategy requires a secret or key



      Even if I move .env into src (same directory as server) and remove path in config, it fails.







      javascript node.js environment-variables






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 16 '17 at 20:39







      softcode

















      asked Feb 16 '17 at 20:21









      softcodesoftcode

      8641638




      8641638
























          4 Answers
          4






          active

          oldest

          votes


















          5














          It appears that when you specify the path, you need to make it full:



          require('dotenv').config({path: __dirname + '/../.env'});


          .env being your file






          share|improve this answer



















          • 2





            Thanks for answering again man. That doesn't work tho

            – softcode
            Feb 16 '17 at 20:35











          • update your question and show us your folder structure, where you have the .env file and where are you trying to call it.

            – yBrodsky
            Feb 16 '17 at 20:36






          • 1





            folder structure is the first code sample, and I'm trying to call it in server.js as in the 2nd code sample

            – softcode
            Feb 16 '17 at 20:37











          • If server.js is inside a subfolder my code should work. What's the output of __dirname?

            – yBrodsky
            Feb 16 '17 at 20:40











          • console.log(__dirname) doesn't output anything because nothing runs in server.js

            – softcode
            Feb 16 '17 at 20:42





















          1














          I'm using require('dotenv').config() on my main nodejs .js entry file and it works just fine.



          From the docs:




          Path



          Default: .env



          You can specify a custom path if your file containing environment
          variables is named or located differently.



          require('dotenv').config({path: '/custom/path/to/your/env/vars'})







          share|improve this answer


























          • I know that your problem is probably not related to the dotenv module, but I still gave a good answer. Your app probably crashes because something else.

            – Omri Luzon
            Feb 16 '17 at 21:40













          • stackoverflow.com/questions/42284820/…

            – Omri Luzon
            Feb 16 '17 at 21:46






          • 1





            Your answer is a link to docs. That was the first thing I read. It's not a good answer sry

            – softcode
            Feb 16 '17 at 21:51











          • My answer includes a link to the documentation, this is how answers should be in stackoverflow. If your problem was an error thrown because of something else, you should at least mention it, and not just open a new question.

            – Omri Luzon
            Feb 16 '17 at 22:55






          • 1





            Your answer literally paraphrases docs. The only non-doc sentences are the ones introducing the docs. Furthermore the next question I asked has nothing to do with this one. Look at the comments to this question to understand the difference before flagging as duplicate.

            – softcode
            Feb 16 '17 at 22:57



















          0














          use may use:



          require('dotenv').config({ path: require('find-config')('.env') })


          This will recurse parent directories until it finds a .env file to use.



          You can also alternatively use this module called ckey inspired from one-liner above.



          .env file from main directory.



          # dotenv sample content
          USER=sample@gmail.com
          PASSWORD=iampassword123
          API_KEY=1234567890


          some js file from sub-directory



          const ck = require('ckey');

          const userName = ck.USER; // sample@gmail.com
          const password = ck.PASSWORD; // iampassword123
          const apiKey = ck.API_KEY; // 1234567890





          share|improve this answer































            0














            Try this; this should work.



            import {} from 'dotenv/config'
            import somethingElse from 'somethingElse'
            ...
            [the rest of your code]


            This works because of how ES6 modules imports modules.



            If you want to dig into more.
            Please refer this. https://hacks.mozilla.org/2015/08/es6-in-depth-modules/




            As a summary :



            When you run a module containing an import declaration, the modules it
            imports are loaded first, then each module body is executed in a
            depth-first traversal of the dependency graph, avoiding cycles by
            skipping anything already executed.




            Hope this will help someone.






            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/3.0/"u003ecc by-sa 3.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%2f42283841%2fdotenv-not-loading-properly%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









              5














              It appears that when you specify the path, you need to make it full:



              require('dotenv').config({path: __dirname + '/../.env'});


              .env being your file






              share|improve this answer



















              • 2





                Thanks for answering again man. That doesn't work tho

                – softcode
                Feb 16 '17 at 20:35











              • update your question and show us your folder structure, where you have the .env file and where are you trying to call it.

                – yBrodsky
                Feb 16 '17 at 20:36






              • 1





                folder structure is the first code sample, and I'm trying to call it in server.js as in the 2nd code sample

                – softcode
                Feb 16 '17 at 20:37











              • If server.js is inside a subfolder my code should work. What's the output of __dirname?

                – yBrodsky
                Feb 16 '17 at 20:40











              • console.log(__dirname) doesn't output anything because nothing runs in server.js

                – softcode
                Feb 16 '17 at 20:42


















              5














              It appears that when you specify the path, you need to make it full:



              require('dotenv').config({path: __dirname + '/../.env'});


              .env being your file






              share|improve this answer



















              • 2





                Thanks for answering again man. That doesn't work tho

                – softcode
                Feb 16 '17 at 20:35











              • update your question and show us your folder structure, where you have the .env file and where are you trying to call it.

                – yBrodsky
                Feb 16 '17 at 20:36






              • 1





                folder structure is the first code sample, and I'm trying to call it in server.js as in the 2nd code sample

                – softcode
                Feb 16 '17 at 20:37











              • If server.js is inside a subfolder my code should work. What's the output of __dirname?

                – yBrodsky
                Feb 16 '17 at 20:40











              • console.log(__dirname) doesn't output anything because nothing runs in server.js

                – softcode
                Feb 16 '17 at 20:42
















              5












              5








              5







              It appears that when you specify the path, you need to make it full:



              require('dotenv').config({path: __dirname + '/../.env'});


              .env being your file






              share|improve this answer













              It appears that when you specify the path, you need to make it full:



              require('dotenv').config({path: __dirname + '/../.env'});


              .env being your file







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Feb 16 '17 at 20:33









              yBrodskyyBrodsky

              3,93611220




              3,93611220








              • 2





                Thanks for answering again man. That doesn't work tho

                – softcode
                Feb 16 '17 at 20:35











              • update your question and show us your folder structure, where you have the .env file and where are you trying to call it.

                – yBrodsky
                Feb 16 '17 at 20:36






              • 1





                folder structure is the first code sample, and I'm trying to call it in server.js as in the 2nd code sample

                – softcode
                Feb 16 '17 at 20:37











              • If server.js is inside a subfolder my code should work. What's the output of __dirname?

                – yBrodsky
                Feb 16 '17 at 20:40











              • console.log(__dirname) doesn't output anything because nothing runs in server.js

                – softcode
                Feb 16 '17 at 20:42
















              • 2





                Thanks for answering again man. That doesn't work tho

                – softcode
                Feb 16 '17 at 20:35











              • update your question and show us your folder structure, where you have the .env file and where are you trying to call it.

                – yBrodsky
                Feb 16 '17 at 20:36






              • 1





                folder structure is the first code sample, and I'm trying to call it in server.js as in the 2nd code sample

                – softcode
                Feb 16 '17 at 20:37











              • If server.js is inside a subfolder my code should work. What's the output of __dirname?

                – yBrodsky
                Feb 16 '17 at 20:40











              • console.log(__dirname) doesn't output anything because nothing runs in server.js

                – softcode
                Feb 16 '17 at 20:42










              2




              2





              Thanks for answering again man. That doesn't work tho

              – softcode
              Feb 16 '17 at 20:35





              Thanks for answering again man. That doesn't work tho

              – softcode
              Feb 16 '17 at 20:35













              update your question and show us your folder structure, where you have the .env file and where are you trying to call it.

              – yBrodsky
              Feb 16 '17 at 20:36





              update your question and show us your folder structure, where you have the .env file and where are you trying to call it.

              – yBrodsky
              Feb 16 '17 at 20:36




              1




              1





              folder structure is the first code sample, and I'm trying to call it in server.js as in the 2nd code sample

              – softcode
              Feb 16 '17 at 20:37





              folder structure is the first code sample, and I'm trying to call it in server.js as in the 2nd code sample

              – softcode
              Feb 16 '17 at 20:37













              If server.js is inside a subfolder my code should work. What's the output of __dirname?

              – yBrodsky
              Feb 16 '17 at 20:40





              If server.js is inside a subfolder my code should work. What's the output of __dirname?

              – yBrodsky
              Feb 16 '17 at 20:40













              console.log(__dirname) doesn't output anything because nothing runs in server.js

              – softcode
              Feb 16 '17 at 20:42







              console.log(__dirname) doesn't output anything because nothing runs in server.js

              – softcode
              Feb 16 '17 at 20:42















              1














              I'm using require('dotenv').config() on my main nodejs .js entry file and it works just fine.



              From the docs:




              Path



              Default: .env



              You can specify a custom path if your file containing environment
              variables is named or located differently.



              require('dotenv').config({path: '/custom/path/to/your/env/vars'})







              share|improve this answer


























              • I know that your problem is probably not related to the dotenv module, but I still gave a good answer. Your app probably crashes because something else.

                – Omri Luzon
                Feb 16 '17 at 21:40













              • stackoverflow.com/questions/42284820/…

                – Omri Luzon
                Feb 16 '17 at 21:46






              • 1





                Your answer is a link to docs. That was the first thing I read. It's not a good answer sry

                – softcode
                Feb 16 '17 at 21:51











              • My answer includes a link to the documentation, this is how answers should be in stackoverflow. If your problem was an error thrown because of something else, you should at least mention it, and not just open a new question.

                – Omri Luzon
                Feb 16 '17 at 22:55






              • 1





                Your answer literally paraphrases docs. The only non-doc sentences are the ones introducing the docs. Furthermore the next question I asked has nothing to do with this one. Look at the comments to this question to understand the difference before flagging as duplicate.

                – softcode
                Feb 16 '17 at 22:57
















              1














              I'm using require('dotenv').config() on my main nodejs .js entry file and it works just fine.



              From the docs:




              Path



              Default: .env



              You can specify a custom path if your file containing environment
              variables is named or located differently.



              require('dotenv').config({path: '/custom/path/to/your/env/vars'})







              share|improve this answer


























              • I know that your problem is probably not related to the dotenv module, but I still gave a good answer. Your app probably crashes because something else.

                – Omri Luzon
                Feb 16 '17 at 21:40













              • stackoverflow.com/questions/42284820/…

                – Omri Luzon
                Feb 16 '17 at 21:46






              • 1





                Your answer is a link to docs. That was the first thing I read. It's not a good answer sry

                – softcode
                Feb 16 '17 at 21:51











              • My answer includes a link to the documentation, this is how answers should be in stackoverflow. If your problem was an error thrown because of something else, you should at least mention it, and not just open a new question.

                – Omri Luzon
                Feb 16 '17 at 22:55






              • 1





                Your answer literally paraphrases docs. The only non-doc sentences are the ones introducing the docs. Furthermore the next question I asked has nothing to do with this one. Look at the comments to this question to understand the difference before flagging as duplicate.

                – softcode
                Feb 16 '17 at 22:57














              1












              1








              1







              I'm using require('dotenv').config() on my main nodejs .js entry file and it works just fine.



              From the docs:




              Path



              Default: .env



              You can specify a custom path if your file containing environment
              variables is named or located differently.



              require('dotenv').config({path: '/custom/path/to/your/env/vars'})







              share|improve this answer















              I'm using require('dotenv').config() on my main nodejs .js entry file and it works just fine.



              From the docs:




              Path



              Default: .env



              You can specify a custom path if your file containing environment
              variables is named or located differently.



              require('dotenv').config({path: '/custom/path/to/your/env/vars'})








              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 13 '17 at 19:17

























              answered Feb 16 '17 at 20:35









              Omri LuzonOmri Luzon

              1,27751427




              1,27751427













              • I know that your problem is probably not related to the dotenv module, but I still gave a good answer. Your app probably crashes because something else.

                – Omri Luzon
                Feb 16 '17 at 21:40













              • stackoverflow.com/questions/42284820/…

                – Omri Luzon
                Feb 16 '17 at 21:46






              • 1





                Your answer is a link to docs. That was the first thing I read. It's not a good answer sry

                – softcode
                Feb 16 '17 at 21:51











              • My answer includes a link to the documentation, this is how answers should be in stackoverflow. If your problem was an error thrown because of something else, you should at least mention it, and not just open a new question.

                – Omri Luzon
                Feb 16 '17 at 22:55






              • 1





                Your answer literally paraphrases docs. The only non-doc sentences are the ones introducing the docs. Furthermore the next question I asked has nothing to do with this one. Look at the comments to this question to understand the difference before flagging as duplicate.

                – softcode
                Feb 16 '17 at 22:57



















              • I know that your problem is probably not related to the dotenv module, but I still gave a good answer. Your app probably crashes because something else.

                – Omri Luzon
                Feb 16 '17 at 21:40













              • stackoverflow.com/questions/42284820/…

                – Omri Luzon
                Feb 16 '17 at 21:46






              • 1





                Your answer is a link to docs. That was the first thing I read. It's not a good answer sry

                – softcode
                Feb 16 '17 at 21:51











              • My answer includes a link to the documentation, this is how answers should be in stackoverflow. If your problem was an error thrown because of something else, you should at least mention it, and not just open a new question.

                – Omri Luzon
                Feb 16 '17 at 22:55






              • 1





                Your answer literally paraphrases docs. The only non-doc sentences are the ones introducing the docs. Furthermore the next question I asked has nothing to do with this one. Look at the comments to this question to understand the difference before flagging as duplicate.

                – softcode
                Feb 16 '17 at 22:57

















              I know that your problem is probably not related to the dotenv module, but I still gave a good answer. Your app probably crashes because something else.

              – Omri Luzon
              Feb 16 '17 at 21:40







              I know that your problem is probably not related to the dotenv module, but I still gave a good answer. Your app probably crashes because something else.

              – Omri Luzon
              Feb 16 '17 at 21:40















              stackoverflow.com/questions/42284820/…

              – Omri Luzon
              Feb 16 '17 at 21:46





              stackoverflow.com/questions/42284820/…

              – Omri Luzon
              Feb 16 '17 at 21:46




              1




              1





              Your answer is a link to docs. That was the first thing I read. It's not a good answer sry

              – softcode
              Feb 16 '17 at 21:51





              Your answer is a link to docs. That was the first thing I read. It's not a good answer sry

              – softcode
              Feb 16 '17 at 21:51













              My answer includes a link to the documentation, this is how answers should be in stackoverflow. If your problem was an error thrown because of something else, you should at least mention it, and not just open a new question.

              – Omri Luzon
              Feb 16 '17 at 22:55





              My answer includes a link to the documentation, this is how answers should be in stackoverflow. If your problem was an error thrown because of something else, you should at least mention it, and not just open a new question.

              – Omri Luzon
              Feb 16 '17 at 22:55




              1




              1





              Your answer literally paraphrases docs. The only non-doc sentences are the ones introducing the docs. Furthermore the next question I asked has nothing to do with this one. Look at the comments to this question to understand the difference before flagging as duplicate.

              – softcode
              Feb 16 '17 at 22:57





              Your answer literally paraphrases docs. The only non-doc sentences are the ones introducing the docs. Furthermore the next question I asked has nothing to do with this one. Look at the comments to this question to understand the difference before flagging as duplicate.

              – softcode
              Feb 16 '17 at 22:57











              0














              use may use:



              require('dotenv').config({ path: require('find-config')('.env') })


              This will recurse parent directories until it finds a .env file to use.



              You can also alternatively use this module called ckey inspired from one-liner above.



              .env file from main directory.



              # dotenv sample content
              USER=sample@gmail.com
              PASSWORD=iampassword123
              API_KEY=1234567890


              some js file from sub-directory



              const ck = require('ckey');

              const userName = ck.USER; // sample@gmail.com
              const password = ck.PASSWORD; // iampassword123
              const apiKey = ck.API_KEY; // 1234567890





              share|improve this answer




























                0














                use may use:



                require('dotenv').config({ path: require('find-config')('.env') })


                This will recurse parent directories until it finds a .env file to use.



                You can also alternatively use this module called ckey inspired from one-liner above.



                .env file from main directory.



                # dotenv sample content
                USER=sample@gmail.com
                PASSWORD=iampassword123
                API_KEY=1234567890


                some js file from sub-directory



                const ck = require('ckey');

                const userName = ck.USER; // sample@gmail.com
                const password = ck.PASSWORD; // iampassword123
                const apiKey = ck.API_KEY; // 1234567890





                share|improve this answer


























                  0












                  0








                  0







                  use may use:



                  require('dotenv').config({ path: require('find-config')('.env') })


                  This will recurse parent directories until it finds a .env file to use.



                  You can also alternatively use this module called ckey inspired from one-liner above.



                  .env file from main directory.



                  # dotenv sample content
                  USER=sample@gmail.com
                  PASSWORD=iampassword123
                  API_KEY=1234567890


                  some js file from sub-directory



                  const ck = require('ckey');

                  const userName = ck.USER; // sample@gmail.com
                  const password = ck.PASSWORD; // iampassword123
                  const apiKey = ck.API_KEY; // 1234567890





                  share|improve this answer













                  use may use:



                  require('dotenv').config({ path: require('find-config')('.env') })


                  This will recurse parent directories until it finds a .env file to use.



                  You can also alternatively use this module called ckey inspired from one-liner above.



                  .env file from main directory.



                  # dotenv sample content
                  USER=sample@gmail.com
                  PASSWORD=iampassword123
                  API_KEY=1234567890


                  some js file from sub-directory



                  const ck = require('ckey');

                  const userName = ck.USER; // sample@gmail.com
                  const password = ck.PASSWORD; // iampassword123
                  const apiKey = ck.API_KEY; // 1234567890






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 14 '18 at 20:01









                  Jorge RosalJorge Rosal

                  273210




                  273210























                      0














                      Try this; this should work.



                      import {} from 'dotenv/config'
                      import somethingElse from 'somethingElse'
                      ...
                      [the rest of your code]


                      This works because of how ES6 modules imports modules.



                      If you want to dig into more.
                      Please refer this. https://hacks.mozilla.org/2015/08/es6-in-depth-modules/




                      As a summary :



                      When you run a module containing an import declaration, the modules it
                      imports are loaded first, then each module body is executed in a
                      depth-first traversal of the dependency graph, avoiding cycles by
                      skipping anything already executed.




                      Hope this will help someone.






                      share|improve this answer




























                        0














                        Try this; this should work.



                        import {} from 'dotenv/config'
                        import somethingElse from 'somethingElse'
                        ...
                        [the rest of your code]


                        This works because of how ES6 modules imports modules.



                        If you want to dig into more.
                        Please refer this. https://hacks.mozilla.org/2015/08/es6-in-depth-modules/




                        As a summary :



                        When you run a module containing an import declaration, the modules it
                        imports are loaded first, then each module body is executed in a
                        depth-first traversal of the dependency graph, avoiding cycles by
                        skipping anything already executed.




                        Hope this will help someone.






                        share|improve this answer


























                          0












                          0








                          0







                          Try this; this should work.



                          import {} from 'dotenv/config'
                          import somethingElse from 'somethingElse'
                          ...
                          [the rest of your code]


                          This works because of how ES6 modules imports modules.



                          If you want to dig into more.
                          Please refer this. https://hacks.mozilla.org/2015/08/es6-in-depth-modules/




                          As a summary :



                          When you run a module containing an import declaration, the modules it
                          imports are loaded first, then each module body is executed in a
                          depth-first traversal of the dependency graph, avoiding cycles by
                          skipping anything already executed.




                          Hope this will help someone.






                          share|improve this answer













                          Try this; this should work.



                          import {} from 'dotenv/config'
                          import somethingElse from 'somethingElse'
                          ...
                          [the rest of your code]


                          This works because of how ES6 modules imports modules.



                          If you want to dig into more.
                          Please refer this. https://hacks.mozilla.org/2015/08/es6-in-depth-modules/




                          As a summary :



                          When you run a module containing an import declaration, the modules it
                          imports are loaded first, then each module body is executed in a
                          depth-first traversal of the dependency graph, avoiding cycles by
                          skipping anything already executed.




                          Hope this will help someone.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Dec 28 '18 at 15:57









                          ChamikaChamika

                          1




                          1






























                              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%2f42283841%2fdotenv-not-loading-properly%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

                              Mossoró

                              Error while reading .h5 file using the rhdf5 package in R

                              Pushsharp Apns notification error: 'InvalidToken'