Scheduler for AdonisJS without Command

AdonisJS is Laravel-like framework written for a Node. If you want to run a task like cron, there is a package called: adonis-scheduler

Assumptions / Requirements

I am assuming that you have already followed the installation steps of adonis-scheduler. Once you are done, following steps is what it takes to make ‘cron-less’ scheduler for your Adonis App

Running Scheduler without Command

Step 1 – Set up Scheduler

Create a file called scheduler.js in start folder with following content:

// start/scheduler.js

'use strict'

const Scheduler = use('Scheduler')

Step 2 – Load with Server

Open server.js file and load the above file with preLoad(‘start/start-scheduler’)

new Ignitor(require('@adonisjs/fold'))

This way, you don’t need pm2 setup and scheduler will not load with ace commands.

Cron syntax for JavaScript

Cron for JavaScript supports second as well as described following:

 # ┌────────────── second (optional)
 # │ ┌──────────── minute
 # │ │ ┌────────── hour
 # │ │ │ ┌──────── day of month
 # │ │ │ │ ┌────── month
 # │ │ │ │ │ ┌──── day of week
 # │ │ │ │ │ │
 # │ │ │ │ │ │
 # * * * * * *

Laravel Alternative in Node – AdonisJS

AdonisJS can be said to be a complete transformation of a Laravel framework in PHP to Node. Consider it in this way – it is a Laravel re-written in Node.

We have used Laravel extensively to create various Shopify Application. The fundamental problem with Laravel is database connections which goes out of hand when you use multiple databases. If you come to node and write some stuff which isn’t AdonisJS, then you will fall under the trap of callbacks and promises. So we needed something which is not only in node – but a lot like Laravel.

AdonisJS has a Query Builder, ORM (LUCID), Scheduler and of course, it is MVC. Adonis follows almost same naming conventions of Laravel – if that be a Controller, Route or anything. The API is so consistent, you can guess it. If you are coming from Laravel directly, you already know! Give it a try and watch screencasts.

AdonisJS an alternative to Laravel