fad
fad

Reputation: 53

microservice with node and needle

I'm trying to make my monolithic application written in node and express to a microservice application in node, needle(to communicate between microservices) and express. My architecture is as follows,

When I try to change my application to microservice I'm doing the following

I'm adding a small code snippet, hoping it will help? Am I doing it in the right way?? when I'm doing as shown below Im getting the error "Cannot set headers after they are sent to the client"

function (req, res, next) {
  var options = {
    headers: req.headers,
    parse_cookies:true
  }
    needle.post(url + "login", req.body, options, function (error, response, body) {
      if (!error) {
        res.writeHead(response.statusCode,response.headers);
        res.send(body)
        console.log(res);
        next();


      } else {
        console.log("error in  info from users micro service");
        res.send(error);
        next();
      }
    });
  },

Upvotes: 0

Views: 250

Answers (0)

Related Questions