Environment variables containing newlines in Node?

后端 未结 8 474
再見小時候
再見小時候 2021-02-02 06:00

I\'m attempting to load an RSA private key into my nodejs application using environment variables, but the newlines seem to be being auto-escaped.

For the following, ass

8条回答
  •  攒了一身酷
    2021-02-02 06:33

    As described in another topic you can encode yout multiline string in base64 and put it inside .env like

    HTTPS_CA_CERTIFICATE=LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURDVENDQWZHZ0F3SUJBZ0lVY29lWFp1R
    

    And then decode it inside your app

    var cert = new Buffer(process.env.HTTPS_CA_CERTIFICATE, 'base64').toString('ascii');
    

提交回复
热议问题