I have many commands and each of them is long. For example, I have:
createreadupdatedeleteI want to put them in separate files:
./commands/create.js./commands/read.js./commands/update.js./commands/delete.jsand I want to require them in app.js:
require('./commands/create.js');
// ...
so I can:
node app.js create HelloWorld
How can I achieve this?
I would do something like this:
// create.js
function create(args, cb) {
// ... your logic
}
module.exports = function (vorpal) {
vorpal
.command('create')
.action(create);
}
Then in your main file, you can do:
// main.js
const vorpal = Vorpal();
vorpal
.use(require('./create.js'))
.use(require('./read.js'))
.show();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With