[英]How to fix nodeJS error: parseFileSync() is not a function
I want to check whether my.env file has environmental file APP_KEY or not.我想检查 my.env 文件是否有环境文件 APP_KEY 。 If it doesn't have APP_KEY, then I am going to create a new one and save the data in.emv fikey This is my following code:-如果它没有 APP_KEY,那么我将创建一个新的并将数据保存在 .emv fikey 这是我的以下代码:-
const generateApiKey = require('generate-api-key');
const fs = require('fs');
const envfile = require('envfile');
const envSourcePath = '.env';
const IS_APP_KEY = process.env.APP_KEY;
if(IS_APP_KEY == null || IS_APP_KEY == '')
{
let parsedEnvFile = envfile.parseFileSync(envSourcePath);
parsedEnvFile.APP_KEY = generateApiKey();
fs.writeFileSync('./.env', envfile.stringifySync(parsedEnvFile))
}
However, I am keep getting an error:- parseFileSync() is not a function但是,我不断收到错误消息:- parseFileSync() 不是 function
How can I solve the problem?我该如何解决这个问题?
the method doesn't exist, it's removed with v6.0.0该方法不存在,已在 v6.0.0 中删除
v6.0.0 2020 May 21 v6.0.0 2020 年 5 月 21 日
Breaking Changes:重大变化:
API is now only stringify and parse API 现在只是字符串化和解析
https://github.com/bevry/envfile/blob/master/HISTORY.md#v600-2020-may-21 https://github.com/bevry/envfile/blob/master/HISTORY.md#v600-2020-may-21
so either install older version, or use new methods所以要么安装旧版本,要么使用新方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.