Call meteor method from the command line

I am thinking of a way to allow users to upload files containing app-data, which would be parsed on the server and subsequently loaded into the database with a method call. A side-effect of this approach would be that it should be possible to do the same on the server, but from the command line. However I am unsure as how to call a method from the command line…

example method:

Meteor.methods({
  'load.file': function(filename){
    //load the file, validate content, insert into database 
  }
})

If I would be able to call this method from the command line this would allow me to insert data with a simple command-line call, or allow users to upload their own data.

Any help would be greatly appreciated!

1 Like

Is this a really weird question? Or is it impossible? Are there better ways to do this? I have experimented a bit with exposing an API, but that seems overly complex?

The standard Meteor.method uses DDP as its connection layer, which is not easy to emulate from a command line (bt which I assume you mean something like bash).

The simplest way to do this is to duplicate your method with a REST endpoint. You can then use curl from the command line.

Add your REST endpoint with one of simple:rest, nimble:restivus or centiq:crud.

Cool, thanks! I have indeed implemented REST endpoints with nimble:restivus, which sort of works the way I want it to.

My main objective was to use the schema validations I have set up within meteor when bulk-loading data into my app. For this I am now using a node.js script that makes http calls to my apps REST endpoints. This seems ineffective to me. Additionally, I found it hard to only expose the REST api on the server, so that it can not be called from the outside world.

Do you know of any examples that set up a DDP connection from a separate node.js script? A bit like I am doing right now with HTTP requests?

You could check these out:

http://www.meteorpedia.com/read/DDP_Clients#Node.JS

1 Like

Arriving late to the party, but now you can just run

echo "Meteor.call('mymethod')" | meteor shell

1 Like

I guess you want something like this : (go to 1:38)

Beware, this package has not been updated for 4 years old :

Interesting to see the bump.

At the moment I am using this: https://github.com/mondora/asteroid

Although this might seems like a little overkill, it allows you to access meteor methods of deployed apps from the command-line.

As an alternative of command line, you can use Meteorman, it is a ddp client with GUI (like Postman but for Meteor)

@diavrank95 will post this tool here:
😎 Awesome Meteor List

Thanks

1 Like