What's New In AdonisJs 4.0

Chimezie Enyinnaya

AdonisJS 4.0 has been in development for quite some time now. Recently Harminder Virk the creator of AdonisJs announced a dev release of the much awaited v4.0 of the framework. In his words:

The framework is full of new and fresh ideas to make you even more productive

In this article, we'll be looking at the new features, enhancements, changes that were introduced in AdonisJs 4.0. We'll start by highlighting them, then take a broader look at each of them in succession.

  • New website design and logo
  • Adonis CLI
  • NPM organization and scope packages
  • Boilerplates
  • New directory structure
  • ES6 features
  • Speed Improvements
  • Edge Templating Engine

New Website Design and Logo

Visiting the dev release, you can’t help but notice the new and beautiful website design and logo.

AdonisJS now has a new theme (colors) which to me is really cooool. I like the new logo too.

Adonis CLI

The Adonis CLI has being improved to include some additional functionality. The CLI now contain a install command which will save you tremendous time when installing npm packages. It does not only install the packages, but at the same time creates the config files, required models, migrations etc.

NPM Organization and Scope Packages

All AdonisJS packages are now grouped into an organisation and are scoped with @adonisjs prefix. This will make it easy to differentiate official AdonisJS packages from the community contributed packages. Below is how you would install AdonisJS Auth package:

adonis install @adonisjs/auth

Boilerplates

It is somehow perceived that AdonisJS is meant for building only full stack applications. Well, that's not all true. AdonisJS can be used for any kind of applications ranging from full stack apps, building APIs to microservices. Hence, with v4.0 you have 3 boilerplates (fullstack, slim and api) which you can choose from when creating a new AdonisJS application. By defaut, the fullstack app boilerplate will be used but you can specify the boilerplate you want by passing --slim or --api-only flag.

// creates a fullstack app
adonis new app-name

// creates a slim app
adonis new app-name --slim

// creates an API only app
adonis new app-name --api-only

Now you can start building your application lean and grow big as the application permits.

New Directory Structure

There has been some significant changes in the way AdonisJS 4.0 apps are structured. Below is screenshot showing the directory structures of each boilerplate.

Note that resources and public directories are not included in the api boilerplate, since the API you will be building with it can be consumed by any frontend or mobile app. You can easily create new directories/files as your application requires using the adonis CLI commands.

ES6 Features

AdonisJS 4.0 makes extensive use of async/await and ES6 Object destructuring. So if you are excited and love these ES6 features then you would definitely love AdonisJS 4.0. The code sample below shows how AdonisJS 4.0 makes use of these features:

// sample code

class UserController {
    async login ({ request, auth }) {
        const { email, password } = request.all()
        await auth.attempt(email, password)

        return 'Logged in successfully'
    }
}

Speed Improvements

AdonisJS 4.0 uses async/await on like the eariler versions which makes use of generators. This has resulted in a huge performance significant in the framework, as v4.0 is almost 4 times faster than earlier versions of AdonisJS. You can take a look at the benchmarks.

Edge Templating Engine

Edge.js is Node.js templating engine, it is blazing fast and comes with an elegant API to create dynamic views. It is created by the creator of AdonisJS. AdonisJS 4.0 makes use of Edge as its templating engine compared to eariler versions which makes use of nunjucks.

Conclusion

So we have taken a look the exciting things that are new to AdonisJS 4.0. Though it is hasn't be finally released, but the creator has clearly pointed out that the API is 100% complete. So you can start building your applications with AdonisJS 4.0 or start upgrading your existing applications. According to Harminder Virk, it's just some documentation that's left before it is officially released.

Chimezie Enyinnaya

13 posts

Software Developer [PHP Laravel JavaScript NodeJS AdonisJS VueJS] | movie lover | run http://openlaravel.com