dashersw / cote

A Node.js library for building zero-configuration microservices.
http://cote.js.org
MIT License
2.35k stars 187 forks source link

time-service.js and client.js not working #229

Closed nanetnanet closed 4 years ago

nanetnanet commented 4 years ago

Downloaded cote-master.zip Unzip to folder. npm install. create sample time-service.js create client.js

node time-service.js (running) node client.js (running but no response, I understood to give time for time-service.js ready. I also modify client for requesting every 1000ms and console log confirmed requests every 1000ms)

So I run >npm test found errors (I'm using node v.12.19.0)

image

kerimhudson commented 4 years ago

I was trying this out yesterday and noticed that the callback should take two arguments, an err and a res value. So it works when doing the following. time-service.js

const cote = require('cote');
const timeService = new cote.Responder({ name: 'Time Service' });

timeService.on('time', (req, cb) => {
    cb(undefined, new Date());
});

client.js

const cote = require('cote');
const client = new cote.Requester({ name: 'Client' });

client.send({ type: 'time' }, (err, time) => {
    console.log(time);
});
dashersw commented 4 years ago

Hello, I tried running your code examples and what we have pointed out in the README — I believe this works well for me, I haven't run into an issue like you mentioned.

If the problem still persists for you, I would be grateful if you could create a repository to replicate the issue.

kerimhudson commented 4 years ago

Hey, I'm not the original poster but I've tried since replicating this issue again and I'm not able to replicate it anymore and get the expected outcome.

I think my issue stemmed more from the type definitions expecting an error and a result in the callback, and not allowing only for a result, so is more an issue with that package, so in turns I assumed that should be the default behaviour.

Screenshot 2020-11-16 at 09 54 21

dashersw commented 4 years ago

Thank you 🙏 cote doesn’t have official type information yet—so there might be inconsistencies.