Should You Use AdonisJs? Things To Consider First

Kashyap Merai | kamerk22
3 min readApr 8, 2019

--

Photo by Mimi Thian on Unsplash

I’m Laravel Developer for the past 2 years and all of you can agree with me that it’s a Framework for Web Artisan. From the past couple of months, I’ve been exploring Nodejs and found some very good frameworks like express.js, hapi.js, koa.js, loopback.js, restify.js, fastify.js, sails.js and few others.

So I started developing the same application prototype in almost all the framework mentioned above ( I left loopback in middle 🤫).

Working with all these frameworks makes me appreciate and admire Laravel more 🥰. With Nodejs I had to put extra efforts on scaffolding and struggling to find reliable NPM libraries rather than focusing on the application part. Besides, I had no intention to left Laravel but I kept exploring and I found AdonisJs.

Introduction: AdonisJs

AdonisJs is Nodejs framework inspired by Laravel and using similar ideas of Dependency Injection and Providers to write flexible and beautiful code. I personally believe anyone come from Laravel background and want to explore Node.js must try AdonisJs. The transition is very smooth and one can quickly get familiar with the framework and let the things done. Laravel is more like a toolkit to quickly bootstrap an application and AdonisJs provide same goodies 🎉 for Nodejs.

Highlights

Folder Structure

AdonisJs follows the same structure as Laravel, which is best suited for small to large scale applications. Like Laravel, AdonisJs has a very convenient folder structure which will keep code organized and clean. Moreover, you can always modify the structure as per your needs.

Lucid-ORM

AdonisJs has first class support for Relational Databases like Postgres and MySQL. Lucid-ORM is built on active record standards. Look at the example:

const adults = await User
.query()
.where('age', '>', 18)
.fetch()

We can also write complex queries with the support of Transactions, DB Joins, MIgrations, Seeds, Factories, and Extensions (Postgres Only).

IOC and Service Provider

One of the major challenges is to manage dependencies in any application. Dependencies might be dependent or independent but if they are not managed properly then it may introduce unexpected bugs and behaviors. AdonisJS provide a very efficient way to manage it through IOC.

Service Providers are used to managing life-cycle of dependencies in AdonisJs. We can also extend the core feature of the Framework by extending Service Providers.

Validator and Sanitize

I always take validation very seriously because how can you even sleep at night without validating your data? Always validate your data, I repeat always. You don’t even realize how much time it’ll cost you later.

AdonisJs provides easy yet powerful validation rules to validate and sanitize data from the incoming requests both manually and at the route level.

'use strict'

class StoreUser {
get rules () {
return {
email: 'required|email|unique:users',
password: 'required'
}
}
}

module.exports = StoreUser

Challenges

Community

Currently, AdonisJs is under active development but the community is small. Due to this, contributors and users are also less so you may find it hard to get answers on Stack Overflow.

Documentation is well written. But I still find some parts missing or need more clarifications. Apart from the documentation, tutorials are very less.

Closing Thoughts

I feel that Support from maintainers is excellent. Most of the time you can find help on Discord and Official Forum.

The community has many great plans for the upcoming version v5. Check out here.

If you have any questions or suggestion please leave the comment below and I’d love to talk!

Social Media

You can follow/contact me from the following links:

📝 Read this story later in Journal.

🗞 Wake up every Sunday morning to the week’s most noteworthy Tech stories, opinions, and news waiting in your inbox: Get the noteworthy newsletter >

--

--

Kashyap Merai | kamerk22

Hello, I am a System Engineer based in Tokyo, Japan – Passionate about Space 🚀, Science 🔭 and Computers 💻