【问题标题】:Node.js hippie API testing module installNode.js hippie API 测试模块安装
【发布时间】:2014-02-07 01:48:56
【问题描述】:

我正在尝试安装 hippie api 测试模块。但是,当我尝试使用 hippie 运行一个简单的脚本时,我不断收到错误消息。

我做了:npm install hippie

并创建了一个名为:search.js 的文件

search.js 里面的代码就这么简单:

var api = require('hippie');
hippie()
.json()
.get('https://api.github.com/users/vesln')
.expectStatus(200)
.end(function(err, res, body) {
  if (err) throw err;
});

然后我运行:node search.js

它总是给我一个错误说

ReferenceError: hippie is not defined

有什么想法吗?

【问题讨论】:

    标签: javascript node.js npm


    【解决方案1】:

    您将hippie 模块的引用保存在名为api 的变量中。使用api 变量或重命名它。

    var hippie = require('hippie');
    hippie()
        .json()
        .get('https://api.github.com/users/vesln')
        .expectStatus(200)
        .end(function(err, res, body) {
            if (err) throw err;
        });
    

    或者:

    var api = require('hippie');
    api()
        .json()
        .get('https://api.github.com/users/vesln')
        .expectStatus(200)
        .end(function(err, res, body) {
            if (err) throw err;
        });
    

    【讨论】:

    • 它给了我 -> SyntaxError: Unexpected token R
    • 我的代码中没有大写的“R”。这个错误一定来自其他地方。
    • 我认为它与另一个测试模块冲突,您是否收到错误?或者你能执行测试吗?
    • 我很抱歉这么说,但你的问题是一个原始的“我不知道如何使用 JS/Node.js”所以我为你修正了一个词。您的代码从未离开我的浏览器窗口。如果没有任何代码或至少没有发生错误的信息,很难说出发生了什么。
    • 我不会问我是否知道如何使用 nodejs。我只是想知道这是否发生在大多数人身上,或者只是我认为这不应该发生。
    猜你喜欢
    • 1970-01-01
    • 2012-07-22
    • 2015-12-08
    • 2011-11-12
    • 2013-03-05
    • 1970-01-01
    • 1970-01-01
    • 2013-07-09
    • 2012-03-22
    相关资源
    最近更新 更多