Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Reading enviromental variable problem in node.js

Here is my excel.js:

    let test = async () => {
         console.log(process.env.DATABASE_HOST);
         .......
    }
    test();

Here is my package.json fragment:

"scripts": {
    .............
    "excel": "cross-env NODE_ENV=development node ./server/excel.js",
    "test": "react-scripts test"
  }

My .env.development is stored in the application root folder.
Here is my .env.development:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

DATABASE_HOST=dbServer

When I execute the following command line in the application root folder:

npm run excel

It should return "dbServer", unfortunately, it returns undefined.
How can I fix it?

>Solution :

Install dotenv package, and require it require('dotenv').config()

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading