NodeJS返回没有停止整个功能

问题描述 投票:0回答:2

我有一个函数,[[enter],它在最里面的readfile里面和里面都包含两个fs.readFile函数,我正在检查txt文件是否包含某个关键字,如果这样做,则应停止整个关键字输入功能。

她就是

enter

函数的样子:async function enter(email, firstName, lastName){ fs.readFile(fileName, function(err, data){ parsedData = JSON.parse(data); email = parsedData.email; fs.readFile('./anotherfile.txt', function (err, data) { if (err) throw err; if(data.includes(email)){ console.log('Stopping function'); return; } }); }); console.log('Continuing with function'); }
问题是,当anotherfile.txt包含关键字时,它不会停止整个功能,而是继续并记录上面的代码中所示的“继续使用功能”。

任何帮助将不胜感激!

node.js return fs
2个回答
1
投票
fs许诺可用Node v11.0.0或您可以像这样const readFile = util.promisify(fs.readFile);

0
投票
这是由于两件事。

-1
投票

第一

© www.soinside.com 2019 - 2024. All rights reserved.