[英]Environment variables doesn't replace '\n' with new line in javascript and throw error:0909006C:PEM routines:get_name:no start line
I connected to my gmail account with google api using service account.我使用服务帐户通过谷歌 api 连接到我的 gmail 帐户。 while doing this, I got credentionals in
.json
file with 'private_key', looks something like:在执行此操作时,我在带有“private_key”的
.json
文件中获得了凭证,如下所示:
-----BEGIN PRIVATE KEY----- MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCfE0lFOu6odsZd vqCrXHbyFvalkMReFi1bo76tjSpNuJkDlHRKlx0ro+VZ0bqifIbo3yRGST+/Bxyr
now, I have to deploy my app, so I added the private_key
to .env
,现在,我必须部署我的应用程序,所以我将
private_key
添加到.env
,
unfortunatly I get this error: Error: error:0909006C:PEM routines:get_name:no start line
.不幸的是,我收到此错误:
Error: error:0909006C:PEM routines:get_name:no start line
。
when console.log the proccess.env.private_key
, I get it like this:当 console.log
proccess.env.private_key
时,我得到它是这样的:
-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCupQiD7fphkibb\nSRJ9x7tJLLWPvL+abF7pUsM30dwSxLtws4O83SFfDnRT9SYebZGz+9EVkv4VtSux\nzOhmLIBc3zUIAQyaD9VZFnZKFf5B0fjD/fp4Oq+AWXtMy
in one long line... and all the \n
is still there instead of being replaced by a new line.在一长串中......并且所有
\n
仍然存在,而不是被新行替换。
let privateKey = process.env.PRIVATE_KEY.replace(/\\n/gm, '\n')
this regex replace the \n
to brake line.此正则表达式将
\n
替换为刹车线。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.