restify.createJsonClient post is not working

934 views Asked by At

I am new node.js developer.

I am trying to send data from node server to other node server that listening on port 3003, using restify createJsinClient.

It seems like the call is never being invoked - I can't see it on the server, and on the other side I don't get any error (although I have an error handler).

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)
            });

and on my client side, I'm having:

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

I can't see any indicator in the client, nor on the sever.

2

There are 2 answers

0
Sridhar On

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

This looks like a javascript object with localhost as key and 3003as value.

API guide suggests a different format. You can try this instead

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

I'm not sure when this happened, but it looks like the client functionality has been moved to a separate module. Try using

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

and run npm i restify-clients --save

This fixed it for me as I was following a book that must have been written before this happened.