How to call a Meteor method from the command line


I have a Meteor app and want to call a server method from the command line, so that I can write a bash script to perform scheduled operations.

Is there any way to either call a method directly, or submit a form which will then trigger server-side code?

I’ve tried using curl to call a method, but either it’s not possible or I’m missing something basic. This doesn’t work:

curl "http://localhost:3000/'myMethod')"

nor does:

curl -s -d "http://localhost:3000/imports/api/test.js" > out.html

where test.js:

var test = function(){

I thought of using a form but I can’t think how to create a submit event because the Meteor client uses template events that then call server methods.

I’ll be very grateful for any help! This feels like it should be a simple thing but has me stumped.

Edit: I’ve also tried phantomjs and slimerjs as run through casperjs.

phantomjs is no longer maintained and generates an error:

TypeError: Attempting to change the setter of an unconfigurable property . ttrockstars

slimerjs errors with Firefox 60 and I can’t figure out how to ‘downgrade’ back to the supported 59, and the option to disable automatic updates of Firefox no longer seems to exist. The error is:

c is undefined

Welcome georgia741 !!

Have a look at the webapp package - that will provide you a URL that you can hit that should then let you do whatever you want.

See especially, this bit:

// Listen to incoming HTTP requests (can only be used on the server).
WebApp.connectHandlers.use('/hello', (req, res, next) => {
  res.end(`Hello world from: ${Meteor.release}`);

Then your url is:


req and res are standard node objects - see their specs here




Hope that helps.


for scheduled operations you can also try