2017-03-08 112 views
0

我目前正在使用节点7.6.0,并且正在尝试npm请求模块2.80.0。该模块通过package.json npm install进行安装。按照他们的简单示例,我立即得到:“失败:无法设置未定义的属性'域'。它是一个直接复制粘贴,除了需要的部分。节点请求模块 - 示例请求失败

var request = require('../node_modules/request/request'); 
request('http://www.google.com', function (error, response, body) { 
      console.log('error:', error); // Print the error if one occurred 
      console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received 
      console.log('body:', body); // Print the HTML for the Google homepage. 
     }); 

我是否缺少某些东西或者是否存在其他依赖项我不知道?

+0

你为什么'require()'''request'模块那样? – mscdex

+0

^^是的,他/她说了什么。它应该看起来更像'require('request');' –

回答

0

我需要它不正确。应该只是node_modules/request。混淆,因为有一个模块导出的请求文件夹内有一个实际的request.js。

// Exports 

Request.prototype.toJSON = requestToJSON 
module.exports = Request