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.
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.
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?