seneca的一段代码(原创)
2017-08-24 15:10 很大很老实 阅读(236) 评论(0) 编辑 收藏 举报var seneca=require('seneca')()
seneca.add({cmd:'wordcount'},function(msg,respond){
var length=0;
if(msg.hasOwnProperty('phrase'))
length=msg.phrase.split(' ').length;
respond(null,{words:length});
});
seneca.act({cmd:'wordcount',phrase:'hello everybody! i love all of you!'},function(err,response){
if(err){
console.log('Error!');
return;
};
console.log(response);
});
seneca.act({cmd:'wordcount'},function(err,response){
if(err){
console.log(err);
return;
};
console.log(response);
});