I have two scripts, let's call them "first" and "second".
(我有两个脚本,我们称它们为“第一个”和“第二个”。)
I have no issue with "first" script, here how it's looks:
(我对“第一个”脚本没有任何疑问,这里看起来是这样的:)
const fetch = require('node-fetch');
console.log(typeof fetch); // prints: function
fetch(URLHERE)
.then(res => res.json())
.then(res => {
console.log(res);
});
And here is a "second" script which won't stop itself after it's run
(这是一个“第二”脚本,运行后不会停止)
const APIWRAPPER = require('APIWRAPPER');
const api = new APIWRAPPER(TOKEN);
console.log(typeof api); // prints: object
api.find(QUERY)
.then(json => {
console.log(json);
});
Both scripts outputs same thing.
(这两个脚本输出相同的内容。)
But when I running "second" script it won't stop.
(但是,当我运行“第二”脚本时,它不会停止。)
I have to press Ctrl + C in my win terminal.(我必须在赢终端中按Ctrl +C。)
And you might ask, is it such a big issue for me to press Ctrl + C once in a while?
(您可能会问,偶尔按Ctrl + C对我来说有太大问题吗?)
No it's not, but I'm trying to trigger this script with GitHub Action and it's just endlessly running leaving me one option: cancel it.(不,不是,但是我试图通过GitHub Action触发此脚本,并且它不断运行,给我一个选择:取消它。)
PS I'm using node run first
and node run second
to trigger those scripts.
(PS我正在node run first
node run second
node run first
node run second
以触??发这些脚本。)
package.json:
(package.json:)
{
...
"scripts": {
"first": "node ./scripts/first.js",
"second": "node ./scripts/second.js"
},
}
What I tried:
(我试过的)
const APIWRAPPER = require('APIWRAPPER');
const api = new APIWRAPPER(TOKEN);
console.log(typeof api); // prints: object
api.find(QUERY)
.then(json => {
console.log(json);
process.exit(0); // Adding this
});
But I'm not sure if it's good practice, it was just first thing I found.
(但是我不确定这是否是好习惯,这只是我发现的第一件事。)
ask by Bromer translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…