How to set process.env from the file in NodeJS?

前端 未结 2 1320
刺人心
刺人心 2020-12-19 02:27

I\'m new to the Node.JS. I found few articles says we can use .env file to setup the process.env variable, e.g.,

PORT = 8081

but when I run

2条回答
  •  隐瞒了意图╮
    2020-12-19 03:17

    Make a config.js file with the following content:

    module.exports = {
        bar: 'someValue',
        foo: 'otherValue'
        ...
    }
    

    Then you can do this in some file:

    const config = require('./config');
    let foo = config.foo;
    

提交回复
热议问题