我有以下代码在Chrome(V8)下正常运行但在节点内部失败:
var id;
id = setTimeout("TimeoutHandler()", 10);
console.log ('SET');
function TimeoutHandler()
{
clearTimeout(id);
console.log ('CLEAR');
}
Run Code Online (Sandbox Code Playgroud)
Chrome输出:
SET
CLEAR
Run Code Online (Sandbox Code Playgroud)
Nodejs输出:
SET
timers.js:110
first._onTimeout();
^
TypeError: Property '_onTimeout' of object [object Object] is not a function
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?谢谢
我已经创建了一个用于发送REST请求的库:
var rest = require('restler');
module.exports = {
beginSession: function()
{
var options = {
method: "GET",
query: {begin_session: '1'}};
rest.get('http://countly/i', options).
on('complete', function(data, response){
console.log('Status: ' + response.statusCode);
});
}
};
Run Code Online (Sandbox Code Playgroud)
问题是每次我使用库并且响应调用时,'on complete'被多次调用:第一次使用方法将仅调用'on complete'一次,第二次使用方法将调用'on complete'两次等等....
我究竟做错了什么?
谢谢何塞
我正在尝试捕获node.js uncaughtException的堆栈跟踪,它适用于不同的错误但不适用于throw()语句:
在异常处理上纠正堆栈跟踪:
$ cat errorFunc.js
process.on('uncaughtException', function(exception) {
console.log('uncaughtException occurred: ' + exception.stack);
});
MyError();
$ node errorFunc.js
uncaughtException occurred: ReferenceError: MyError is not defined
at Object.<anonymous> (/home/jolcese/code/WebEnclaves/Server/errorFunc.js:5:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
$
Run Code Online (Sandbox Code Playgroud)
缺少由throw()引起的异常堆栈跟踪:
$ cat errorThrow.js
process.on('uncaughtException', function(exception) {
console.log('uncaughtException occurred: ' + exception.stack);
});
throw('my error');
$ node errorThrow.js
uncaughtException occurred: undefined
$
Run Code Online (Sandbox Code Playgroud)
知道为什么吗?
谢谢何塞
免责声明:我知道使用process.on('uncaughtException')是一件非常非常糟糕的事情,我将受到惩罚,但在此代码中使用域名不是一个选项.
我有一个配方在ruby_block中设置变量,需要使用该变量作为配方的输入属性.ruby_block执行后如何使用include_recipe?
谢谢
ruby_block "evaluate_config" do #~FC014
block do
file = File.read('/opt/config/baselogging.json')
data = JSON.parse(file)
node.default['kibana']['apache']['basic_auth_username'] = data['KibanaUser']
node.default['kibana']['apache']['basic_auth_password'] = data['KibanaPassword']
include_recipe 'kibana'
end
end
Run Code Online (Sandbox Code Playgroud)