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.

Simple Role-based Validation Techniques for AdonisJS
· ☕ 2 min read
AdonisJS does not provide an access control list (ACL) feature out of the box. Here’s are a few simple ways to provide the right access to the right user when using AdonisJS. Use ACL plugins There are two plugins available for AdonisJS - Adonis ACL Advanced Adonis ACL The usage is pretty simple.

Custom Exceptions in AdonisJS
· ☕ 2 min read
AdonisJS provides streamlined ways to raise exceptions in your controller or service code, and raise them in a controlled way to the caller. To create a custom exception - 1 adonis make:exception RecordNotFoundException This will create - 1 √ create app\Exceptions\RecordNotFoundException.js Edit the exception to introduce your own errors.

Track Created By / Modified By for Records in AdonisJS
· ☕ 1 min read
AdonisJS provided a quick way to track created and updated times, but does not provide shortcuts to track the user who created or last updated the record. Doing so is quite easy. Modify the migration script to include created_by_id and updated_by_id. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 // todoschema.

The Right Way to Receive Parameters in AdonisJS Controller
· ☕ 2 min read
Quickly and easily pass parameters to controller methods from your request. See Start creating your backend application in AdonisJS to get started You can quickly scaffold a controller in Adonis using the following command - 1 adonis make:controller Todo --type http If you want to receive parameters from input, you would do the following -

Create a functional backend in AdonisJS under 5 minutes
· ☕ 5 min read
AdonisJS provides a really quick way to scaffold your way to a great back-end application. Let us start creating a simple to-do app called ‘ado’ in this post. We will see how we can create this with simple commands and have your API ready in no time. Install AdonisJS Download and install Node if you don’t have it in your system.

Why should you use AdonisJS framework?
· ☕ 3 min read
AdonisJS is a great server-side framework built on Express. It’s opinionated way of doing things just makes sense, clears up the initial development problems, and makes development & maintenance easier. I have completed ~3 projects on AdonisJS so far after switching roles to a web application developer last year. After using FeathersJS, Laravel and a bit of .

Who's afraid of recursion?
· ☕ 2 min read
Spoiler alert: I am. What is recursion anyway? A program calling itself. How does it look? conquerPlanet() { // infinite loop - there are too many planets to conquer conquerPlanet(); } OK.. how about a practical use case? Well, I am not quite a ‘theory’ guy. But here you go with the age old problem of calculating factorial.

Save 1.618 per day developing stuff
· ☕ 3 min read
Most of my coding a few years back consisted of the following actions - Type slowly Type (a lot of) mistakes Use spaces and tabs to format. Get confused about loops and add ad-hoc spaces and tabs Curse my typing skills and the soul who invented spaces and tabs While formatting code was also becoming an interim ‘thought provoker’, it was simply too much typing.