从node.js中的另一个文件调用一个函数

时间:2013-11-13 08:11:59

标签: javascript node.js

在下面的job.js节点脚本中,如何调用/getJobs .Am使用以下方式,但获取$ is not defined.

job.js

var jobScedule = function (time, jobid) {
var params = {
            "id": jobid
        };
          $.get('/getJobs', params, function (data) {
            console.log(data);
        });
}

的script.js

.......
......
 switch(context.pathname) {
        case '/getJobs':
          testUtils.runTest(context);
          break; 
}

1 个答案:

答案 0 :(得分:1)

您需要request module。它将帮助您发出http请求:

var request = require('request');
request('http://www.google.com', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body) // Print the google web page.
  }
})