Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 当.env文件存在时,为什么dotenv retur未定义?_Node.js_Undefined_Dotenv - Fatal编程技术网

Node.js 当.env文件存在时,为什么dotenv retur未定义?

Node.js 当.env文件存在时,为什么dotenv retur未定义?,node.js,undefined,dotenv,Node.js,Undefined,Dotenv,我有以下问题。“.env”文件不存在。当我解压.env文件并尝试从中读取参数时,我收到“undefined”。当我再次运行我的应用程序和.env文件时,它运行良好。解压后,如果文件在那里,为什么会收到“未定义” I have following function: function envRead(){ require ('dotenv').config({path:'c:/ImageDISM/.env'}); const fi = process.env.FOLDER_IMAGES; co

我有以下问题。“.env”文件不存在。当我解压.env文件并尝试从中读取参数时,我收到“undefined”。当我再次运行我的应用程序和.env文件时,它运行良好。解压后,如果文件在那里,为什么会收到“未定义”

I have following function:

function envRead(){
require ('dotenv').config({path:'c:/ImageDISM/.env'});

const fi = process.env.FOLDER_IMAGES;
const fd = process.env.FOLDER_DATA;
const fn = process.env.FILE;
const dbn = process.env.DB;

return {
        fi,
        fd,
        fn,
        dbn
        };
}

module.exports = {envRead}

part of app.js
.
.
.
console.log(fileArgs[1]);

extract(`c:\\ImageDISM\\${fileArgs[1]}`, {dir:"c:\\ImageDISM/"}, function (err) {
   // handle err
   console.log(err);
})

sleep(10000).then(() => {
    fs.access("c:/ImageDISM/.env", fs.constants.F_OK | fs.constants.W_OK, (err) => {
      if (err) {
        console.error(
          `"c:/ImageDISM/.env" ${err.code === 'ENOENT' ? 'does not exist' : 'is read-only'}`);
      } else {
        console.log("c:/ImageDISM/.env exists, and it is writable");
      }

          fi = resultenvr.fi;
          fd = resultenvr.fd;
          fn = resultenvr.fn;
          dbn = resultenvr.dbn;
         console.log(`image adresare: ${fi}`);
         console.log(`cilovy adresar: ${fd}`);
         console.log(`jmeno souboru: ${fn}`);
         console.log(`database: ${dbn}`);
         });
})
.
.

我认为您需要等待文件提取完成。我也不知道在哪里使用
envRead
function.const resultenvr=envr.envRead();fi=resultenvr.fi;fd=resultenvr.fd;fn=resultenvr.fn;dbn=resultenvr.dbn;如何等待?好吧,我想你在分享的片段中少了那一行。您是否尝试过在提取回调中移动所有fs.access代码?是的,很遗憾,这没有帮助。当文件在运行app.js之前存在时,它工作正常,但当我通过解压(解压缩)来“创建”文件时,它就不工作了。我认为您需要等待文件解压缩完成。我也不知道在哪里使用
envRead
function.const resultenvr=envr.envRead();fi=resultenvr.fi;fd=resultenvr.fd;fn=resultenvr.fn;dbn=resultenvr.dbn;如何等待?好吧,我想你在分享的片段中少了那一行。您是否尝试过在提取回调中移动所有fs.access代码?是的,很遗憾,这没有帮助。当文件在运行app.js之前存在时,它工作正常,但当我通过解压(解压缩)来“创建”文件时,它就不工作了。