从节点模块加载一个库到nodeJS

我在win 7上运行,并已经安装nodeJS作为pathvariables。

我已经安装了一个nodeJs模块( 推进器 ):

运行我的脚本时,我得到:

require('pusher-client') var API_KEY = 'cb65d0a7a72cd94adf1f' var pusher = new Pusher(API_KEY); var channel = pusher.subscribe("ticker.160"); channel.bind("message", function(data) { console.log(data); var topbuy = data.trade.topbuy; console.log("Price: ", topbuy.price, "Quantity:", topbuy.quantity, "Timestamp:", data.trade.timestamp); }); 

错误信息:

 $ node pusher.js c:\xampp\htdocs\projects\psher\node_modules\pusher.js:9 var pusher = new Pusher(API_KEY); ^ ReferenceError: Pusher is not defined at Object.<anonymous> (c:\xampp\htdocs\projects\psher\node_mo dules\pusher.js:9:18) 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:902:3 

我想用require("insert node_module")该库是由nodeJS加载,可以使用?

任何build议我做错了什么?

我感谢你的回答!

你想保存require命令的返回值 – 这将是推模块的输出。 如果推出者输出一个构造函数,你只想写:

 var Pusher = require('pusher-client'); 

然后推杆应该被定义,并可以按照你的方式使用。 (顺便说一句,我从链接推模块自述复制该行)

(另外:不要依靠自动分号插入在行尾,这是不好的做法。)