This page looks best with JavaScript enabled

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 -

adonis new awesomeness --api

AdonisJS comes with a neat set of powerful features -

  1. An ORM that works quite well
  2. Authentication and security already setup
  3. Basic features to serve API without pulling a thousand wires just to get started

The Case for a New Boilerplate

Even with all the features baked in the default boilerplate, I tend to just copy older projects -

  1. AdonisJS has not changed much over the last year
  2. The additional features that I added over time are invaluable in saving time at the very beginning
  3. It takes away the boring tasks of “setting up stuff”

Unfortunately, the simple copy/paste model (even when using older Git commits) were not clean and not friendly to other developers.

So then.. I started using a simple starter template (or a booster template) to start all my AdonisJS projects.

Here’s presenting adonis-api-boost.

What does the starter template contain?

The standard set of components of the starter project/ boilerplate provide a more consistent and standard experience while starting new projects.

The template is just a boilerplate on top of the AdonisJS provided boilerplate. It consists of additional packages for real-world apps (in my opinion), configured functionality and examples.

Packages

The major additional packages are -

  • @adonisjs/mail: Mail people using SMTP or third party mail providers
  • @adonisjs/persona: User registration, password change, & related paraphernalia
  • @adonisjs/validator: Validate data in routes, sanitize data (also, required by persona)
  • adonis-scheduler: Schedule jobs
  • pg: Connect to PostGRE database. Remove this if you are using other DBs

We also register these packages and have examples of how they work (for e.g. a daily scheduled job that does nothing).

Key Features

  • Complete user registration, change password flow with email - thanks to Persona and Mail
  • Use mail templates and do mail-merge (replace placeholders in template with data) using AdonisJS views
  • Add ‘sensible’ user attributes like status, start date, etc. See the user migration file for user
  • Simple authorisation flow using user role. See app/services/AuthorisationService.js to know more
  • A sample Service Request entity that demonstrates authenticated routes
  • Sample batch job that runs daily

Using the boilerplate

Clone this repository to start..

git clone https://github.com/techformist/adonis41-api-boost.git

Install packages -

cd adonis41-api-boost
npm i

Now you continue your work as in any other AdonisJS project.

  • Run the following command to run startup migrations.
    adonis migration:run

  • Run the project in dev mode
    adonis serve --dev

See API usage examples on the repo’s README.

Conclusion

None of the additional packages or features in the starter template add anything significantly new, but required at least half a day to set everything up.

And.. we had consistency issues with the fields used in the standard entities / controller logic. Hopefully we add more useful stuff as we use AdonisJS more and when the next major release happens.

Stay in touch!
Share on

Prashanth Krishnamurthy
WRITTEN BY
Prashanth Krishnamurthy
Technologist | Creator of Things