Run Loopback model method through a single command in a non-interactive way.
npm install loopback-runA tool to launch Loopback method with a single command in a non-interactive way.
A complementary tool of Loopback-console.
In your loopback project
1. npm install --save-dev loopback-run
1. npx loopback-run UserAccount.find
1. npx loopback-run UserAccount.create --username test --email test@localhost --password test123
You can path all the options for loopback-run before a -- if you need
to use options for the method itself
npx loopback-run UserAccount.findOne --exit -- --where.username=test
If you dont have method options you can do npx loopback-run UserAccount.findOne --exit
#### --exit
Close all opened datasource and force exit
Needed if you open persistent connection outside of loopback datasources
#### --loopbackPath
Define a custom path for loopback entry point.
You can use the environnement variable LOOPBACK_PATH as well.
#### --argsFile
Provide a javascript file with exported options, will be merge with
other options provided
#### --json
All output will be serialize with JSON.stringify
#### --argsAsJson
Parse a json string as args for the loopback method
npx loopback-run MyModel.task --argsAsJson '{"where": {"prop.subprod": "value"}}'
You can provide a EventEmitter in the promise to display progress
``javascript
const _ = require('lodash');
const Promise = require('bluebird');
SampleModel.task = function(){
const eventEmitter = new EventEmitter();
let done = 0;
const promise = Promise.mapSeries(_.times(100), async () => {
await Promise.delay(_.random(10, 500));
eventEmitter.emit('progress', {done: ++done, total: 100});
});
promise.events = eventEmitter;
return promise;
}
`
DEBUG=loopback-run npx loopback-run MyModel.task`