Search code examples
node.jsexpressmeteortwitter-digits

What is the equivalent of Express res.send() in Meteor?


I'm trying to use the res.send() from Express into a Meteor project without using a Meteor package like glittershark:meteor-express: https://github.com/glittershark/meteor-express

I'm wondering if there is a solution just using Meteor rather than adding Express on top of Meteor? In particular, how do I use res.send() in Meteor? http://expressjs.com/4x/api.html#res.send

This is the NodeJS code snippet from https://github.com/twitterdev/cannonball-web/blob/master/routes/index.js

var express = require('express');
var router = express.Router();
var request = require('request');

request.get(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
  // Send the verified phone number and Digits user ID.
  var digits = JSON.parse(body)
  return res.send({
    phoneNumber: digits.phone_number,
    userID: digits.id_str,
    error: ''
  });
}

One great answer posted a year ago suggests using fibers. Meteor has undergone a lot of changes since this post and I'd like to avoid fibers: Is there an easy way to convert an express app to meteor?

I'm adding this link to another relevant answer posted that might be helpful in anwering my question: Porting Express App to Meteor

Thanks for reading. :)


Solution

  • There are many good, simple ways you can add a rest api that serves json to a meteor app (I recommend restivus), however the requirements you are forcing on yourself are only going to make it difficult for you.
    WebApp.connectHandlers and connect is the low level apis that you can use, but you are only asking for further difficulties by wanting to avoid Fibers, as this simply is how things are done in Meteor.

    Rather then trying to force square pegs into round holes, I suggest you do one of the two following options: