A Meteor app as a NPM module? #ReactNative

Hello all,

I’m working on a project in React Native and want to connect to a Meteor server using a headless Meteor client (Meteor on the client without Blaze). I am well aware of Asteroid, which is fine, but I’d like to leverage Meteor itself, perhaps as a package. Something like:

myMeteor = require(‘meteor-app’)
// Someone indicate http://myawesomeapp.com as the location of my Meteor app
AwesomeCollection = myMeteor.AwesomeCollection

foo = myMeteor.Meteor.call(…)

AwesomeCollection might be a GroundDB collection or Collection2/SimpleSchema etc.

Any advise steering me in the right direction would be much appreciated. My initial thoughts are to use something like Demeteorize yet not totally clear on the details.

1 Like

I’m thinking that since Meteor packages itself into the client browser or Cordova, it should be that difficult for it to be simply decoupled and included as anyone might wish, in this case, within React Native; yet broadly speaking anywhere Javascript runs.

You can use https://www.npmjs.com/package/ddp to connect to a meteor server, call meteor methods on the server and observe collections.

1 Like

Hey Riaan53, of course. Actually Asteroid is even better than DDP and full Meteor would be even better than that. You are aware of Asteroid? https://github.com/mondora/asteroid

My question is broader, the ability to package a Meteor project into an NPM package lets would theoretically let it be used fully within any JS front-end framework and give it far greater exposure.

Thanks, B

Ok cool :slight_smile: Sorry thought that was what you ment. I havnt used Astroid before but am aware of it.

What package/functionality in particular do you need on the react native (in stead of blaze) client side?

Great question actually it got me thinking about how I wanted it all just headless. Meteor.Tracker, Meteor.subscribe, all the collections, blaze independent packages, etc.

I came across a great article by Ronen Babayoff on running Meteor on the command line, without Blaze. I’m still working this out and any suggestions by you or anyone appreciated.



Hmm… I’ve found something similar to my question for Appcelerator/Titanium here:


Another quick way to get meteor integrated with ReactNative or Titanium is to build an empty meteor app which will generate the necessary clientside js file. Create an npm package with the generated clientside js file. You will need to export the right properties from the clientside js file to be accessible in your ReactNative/Titanium app.

The downside is anytime you add a new meteor package you need in your native app, you will have to repeat the suggested process.

Hey @emmanuelbuah, that is a great suggestion and what I was thinking as well; yet how do we pass in the location of the Meteor server / Mongo to the client script from within the context of require? These are normally environment variables. (process.env.FOO = ‘value’; // won’t work on the client)

I’ve read many people mention utilizing the client bundle of Meteor, yet no pattern for this online. So perhaps my question is really this:

How do I pass in the environment variables Meteor’s client expects from within the context of it being included via require?

Your point about having to repeat the process is true; i’d automate it. There is another consideration that I’ve learn about as well. That web-sockets need to be polyfilled on both React Native and Native Script.



PS -
@raix , here you mention something similar to what @emmanuelbuah suggests above:

“ok. how about setting the URL for web sockets and mongo?”
“We can set settings like in the index.html page”

If you can expound on that a bit, I’d appreciate it.