Build a Simple News App using Adonis v5
· ☕ 23 min read
AdonisJS has been my framework of choice to get stuff done quickly. The framework has taken a turn for the good with more frequent updates to its latest version - v5, which features Typescript, the same trusted MVC framework, and “everything & kitchen sink” approach that is quite effective to easily build apps.

Starter Template for AdonisJS
· ☕ 3 min read
I have used AdonisJS in and out of projects in the last year. Despite it’s smaller community and not-so-regular enhancements, it remains one of my favourite NodeJS frameworks. I recommend AdonisJS for hobby and production projects in full confidence :) I typically use AdonisJS for back-end, which has me start with -

Prevent test emails going out to users in AdonisJS
· ☕ 2 min read
Here’s a quick way to prevent emails from going out in test environments in AdonisJS. We typically end up getting production data in part or in whole to test environments for a “proper” round of testing on real data. But all the data attributes cannot be so “real”. We typically end up changing fields like emails so that customers do not start receiving emails from non-production environments.

Use MySQL Load Files Data in AdonisJS
· ☕ 4 min read
Use MySQL load data function to load data from files within within AdonisJS services. You can perform batch data and file operations efficiently using database utilities. The logic will likely be quicker, lighter on resources, and overall, more suited for batch jobs. Loading data from files is not as sought-after as in the good-ol’ days, but is quite common in enterprise applications.

Batch Operations in AdonisJS
· ☕ 2 min read
Use Adonis Scheduler to create batch tasks as well as schedule execution of said tasks. Adonis Scheduler improves your efficiency in writing batch jobs. I am talking about bulk operations that may or may not be suitable for your general purpose service and controllers. Although scheduler’s purpose seems to be, well, scheduling stuff we can reuse Tasks enabled by scheduler to run bulk operations.

Using Lucid vs. Database Raw in AdonisJS
· ☕ 2 min read
Lucid ORM, the official ORM of AdonisJS, is based on knex.js. It is one of the friendlier ORMs that provides the ease of using a readable syntax along with a better performance than some of the feature-heavy ORMs. But, I have been recently torn between using one or the other.

Manage incremental changes to database in AdonisJS
· ☕ 2 min read
Use database migration utilities in Adonis to its complete potential. Carry out incremental updates - may it be a new table, or changes to existing table using distinct migration files that are version controlled. You have a beautiful Todo application that has a todos table with the following columns: description status end_date Now, let’s say our users ask for a new field called planned_end_date.

Handle Creation of Single or Multiple Records in AdonisJS
· ☕ 2 min read
Support creation of a single record or a group of records using same business logic and in the same controller in AdonisJS. Typically you create the following controller to handle record creation - 1 2 3 4 5 6 // TodoController.js async create({ request, auth }) { const data = request.

Custom Configuration Parameters in AdonisJS
· ☕ 1 min read
AdonisJS stores its configuration values in config folder in root. For e.g. you will set database environment values in database.js, authentication params in auth.js and so on. You can update or set new configuration parameters required by your application in those files. You could also create a new configuration file for your application variables and refer to those values from services, controllers, or from any place where it makes sense.

Pagination in AdonisJS
· ☕ 3 min read
AdonisJS provides a standard way to handle pagination and query only a pre-defined number of records in your query result. A typical controller without any pagination looks like the below - 1 2 3 4 5 6 7 8 // TodoController.js const Todo = use("App/Models/Todo"); class TodoController { async index({ request, response, view }) { return await Todo.

Role-based Access to Routes in AdonisJS
· ☕ 2 min read
AdonisJS provides a standard way to define a middleware and enable access to routes based on defined validation rules. This middleware is leveraged to allow role-based access to routes. Your start | routes.js file will have something akin to below - 1 2 3 4 5 const Route = use("Route"); Route.

Change Date Formats in AdonisJS
· ☕ 3 min read
AdonisJS internally uses moment.js and processes all dates in YYYY-MM-DD format. The format, being an international standard, should have been the standard everywhere. Since it is not, let us see how we can modify the date format. Consider an example - Todo has a end_date field against every record. Your model will look like the below -

Return Related Record Post Saving Record in AdonisJS
· ☕ 1 min read
AdonisJS automatically returns the base/parent record to the caller from the controller. However, you may have to custom code all of one statement to return a related record after the parent record is committed to the database. Consider an example - 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // TodoController.