How do I setup the dotenv file in Node.js?

前端 未结 30 1145

I am trying to use the dotenv NPM package and it is not working for me. I have a file config/config.js with the following content:



        
30条回答
  •  一整个雨季
    2020-12-07 14:40

    This is how i fix my issue

    Intially had this in .env of the root of my project

    const db_port = 90101
    const db_host="localhost"
    const db_username="name"
    const db_password="pwd"
    const db_name="db"
    

    And all my env variables where undefined.

    I fixed it by removing all the const and using just key=value insted of const key="value"

    db_port = 90101
    db_host=localhost
    db_username=name
    db_password=pws
    db_name=db
    

提交回复
热议问题