我正在按计划在Heroku上运行该组件,但无法使其正常运行。我遵循了这个和这篇文章,以使其正常工作。我根据设法在heroku上运行了计划的任务heroku logs
。我的问题是,如果我在模块中运行代码(我需要按计划运行),则它不会运行X射线模块,并且我不确定为什么会这样。
如果我根据此处附带的链接之一运行bin文件夹中的代码,则这是我的没有模块的代码及其输出,这是heroku将执行的任务:
var Xray = require('x-ray');
// helpers
var x = Xray({
filters: {
cleanPrice: function (value) {
return typeof value === 'string' ? value.replace(/\r|\t|\n|€/g, "").trim() : value
},
whiteSpaces: function (value) {
return typeof value === 'string' ? value.replace(/ +/g, ' ').trim() : value
}
}
});
console.log("START - Scraping categories...");
x('http://google.com', 'title')(function (err, title) {
console.log(title) // Google
})
λbin \ node init START-抓取类别... Google
这是我在模块中的代码和输出
module.exports = {
start: function () {
var Xray = require('x-ray');
// helpers
var x = Xray({
filters: {
cleanPrice: function (value) {
return typeof value === 'string' ? value.replace(/\r|\t|\n|€/g, "").trim() : value
},
whiteSpaces: function (value) {
return typeof value === 'string' ? value.replace(/ +/g, ' ').trim() : value
}
}
});
console.log("START - Scraping categories...");
x('http://google.com', 'title')(function (err, title) {
console.log(title) // Google
})
}
}
输出
λbin \ node init START-抓取类别...
我缺少“ Google”一词。如果将代码放在模块中,为什么会发生这种情况???
问题出在实际任务中
#! /app/.heroku/node/bin/node
"use strict";
var app = require('../src/app.js');
function initScrape() {
app.start();
}
initScrape();
process.exit(1); // tell node to exit (prevent promise)
通过添加,process.exit(1);
我阻止了要解决的任何诺言。这是nodejs停止执行所必需的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句