【问题标题】:restify.createJsonClient post is not workingrestify.createJsonClient 帖子不起作用
【发布时间】:2017-08-15 06:42:11
【问题描述】:

我是新的 node.js 开发者。

我正在尝试使用 restify createJsinClient 将数据从节点服务器发送到侦听端口 3003 的其他节点服务器。

似乎从未调用过该调用 - 我在服务器上看不到它,而在另一端我没有收到任何错误(尽管我有一个错误处理程序)。

sender =  restify.createJsonClient({localhost:3003, version: '*'});
sender.post(sender.url, {userName: user, ID: id}, function (err) {
                if (err) {
                    console.error(err);
                }
                console.log("user - %s sent. ", user)
            });

在我的客户端,我有:

let express = require('express');
let app = express();
app.post('/', function (){
    console.log ('new user');
});

我在客户端和服务器上都看不到任何指标。

【问题讨论】:

    标签: node.js http express post restify


    【解决方案1】:

    restify.createJsonClient({localhost:3003, version: '*'});

    这看起来像一个以localhost为键和3003为值的javascript对象。

    API guide 建议使用不同的格式。你可以试试这个

    var sender = restify.createJsonClient({
      url: 'http://localhost:3003',
      version: '*'
    });
    

    【讨论】:

      【解决方案2】:

      我不确定这是什么时候发生的,但看起来客户端功能已移至单独的模块。尝试使用

      var client = require('restify-clients');

      然后运行npm i restify-clients --save

      这为我解决了这个问题,因为我正在关注一本必须在这发生之前写的书。

      【讨论】:

        猜你喜欢
        • 2018-12-15
        • 2018-12-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多