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')
Scheduler.run()

Step 2 – Load with Server

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

new Ignitor(require('@adonisjs/fold'))
  .appRoot(__dirname)
  .preLoad('start/scheduler')
  .fireHttpServer()
  .catch(console.error)

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
 # │ │ │ │ │ │
 # │ │ │ │ │ │
 # * * * * * *

Ease your Node Web development with these 10 npm packages.

When we code, we often don’t rely on single bulkier packages. Since a bulkier framework would tie you up and some of its core-functionality isn’t really good for your app performance or maintainability.

For instance, you would like to bring your own ORM which you are using in small to big products. A native ORM is more likely to support more drivers than a full-fledged framework.

Top 10 must have npm packages

  1. Express – Express framework is extremely lightweight and many developers have expanded it. You can find many extensions of express in npmjs site.
  2. Moment – Moment is a goto package for time-based calculation or formatting time.
  3. Sequelize Or Mongoose – Sequelize is an AR-based ORM and support multiple relational databases. It comes with all the important functionality. File mongoose is for MongoDB
  4. Gulp – Depending on your choice, you would want Grunt or Gulp, my personal choice is Gulp as it gives more control.
  5. Bluebird – More of the advanced promises features are available in this package. My personal favorite is Promise.race.
  6. Lodash – Lodash comes up with a lot of small functions which you can use to modify, manipulate data.
  7. Chalk – Chalk is a complete solution to style terminal
  8. Bunyan – Bunyan enables you to format codes in more readable and expressive
  9. Got – Got is the most powerful package to send out requests.
  10. Webpack – Webpack bundles the javascript for a browser.