Why Choose the AdonisJs Framework? | Full-Stack Google Contacts Clone with AdonisJs (Node.js) and Quasar Framework (Vue.js)

Why Choose the AdonisJs Framework? | Full-Stack Google Contacts Clone with AdonisJs (Node.js) and Quasar Framework (Vue.js)

Table of contents

No heading

No headings in the article.

There are numerous Node.js frameworks which can be used to build API server for your application. So, why am I choosing the AdonisJS framework for this series? The simple answer is that AdonisJS is amazing! I can see you roll your eyes at such a shallow answer but let me tell you a story.

Late 2018, I had finished learning JavaScript and PHP. I chose Laravel - which is now the defacto backend framework for PHP - as the framework to learn and get started on building full-stack applications. Along the way I got bored. Truth be told, I never really liked PHP that much. Then I got to know that I could use my JavaScript skills to build server-side applications through Node.js. It was one of the transformative information I got and literally accelerated my journey in web development. I began to search for Node.js framework which I could use. I came across popular ones such as Express.js and Fastify.js but something in me did not like them. I was already spoilt by the beauty and expressiveness of Laravel, so those frameworks did not tickle my fancy. So I decided to search for a Laravel-like framework for Node.js. Voila! I stumbled upon AdonisJS.

I might have stumbled on AdonisJS because I needed a framework like Laravel but that wasn't why I've pitched my tent with the framework for 3 year now. You see, AdonisJS was initially heavily inspired by Laravel (as admitted the founder and now my good friend - Harminder Virk), but along the way AdonisJS created its own persona, brand, and style which is still unrivalled in the Node.js ecosystem. AdonisJS adopted the same doctrine used in Ruby on Rails including Convention over Configuration. You can read more the Principle of Convention over Configuration from Rails' founder here. You see AdonisJS introduced fluency and expressiveness into the Node.js ecosystem. Even if you are a non-programmer, you can read through the controller files of AdonisJS and totally understand what the programmer was trying to accomplish. It is that beautiful.

Look at an example from this query where a particular company is fetched with all its relations:

    const company = await Company.query()
        .where('id', requestedCompany.id)
        .preload('companySize', (query) => query.select('id', 'size'))
        .preload('country', (query) => query.select('id', 'name'))
        .preload('state', (query) => query.select('id', 'name'))
        .preload('companyLogo', (fileQuery) => fileQuery.select('formats', 'url'))
        .first()

Or this query where we want to create a new customer and associate it with a company automatically

const newCustomer = await requestedCompany?.related('customers').create({
      customerTitleId: title,
      firstName: first_name,
      lastName: last_name,
      middleName: middle_name,
      email,
      phoneNumber: phone_number,
      isCorporate: is_corporate,
      corporateHasRep: corporate_has_rep,
      companyName: company_name,
      companyPhone: company_phone,
      companyEmail: company_email,
})

AdonisJs believes in providing developing developer with best practices (conventions) out of the box with minimal configurations so that you can immediately focus on build your backend. AdonisJs also comes with lots of built-in packages and officially-maintained addons so that you immediately begin writing your code and don't worry about installing third-party extensions and sticking them together with more glue codes.

When you comfortable enough and need to extend the framework with custom features, AdonisJs provides interfaces and hooks for extending the core of the application and even extending the built-in packages.

Checkout the AdonisJS at a glance page for a beautiful summary of the features of the framework.

Some other features of the AdonisJs framework which you will love include:

  1. Community. The community on GitHub and Discord is the best I've seen with members providing timely answers to issues you might have. The core team members including Harminder Virk are always available to assist with tougher questions.
  2. Docs. The documentation for AdonisJs is well-written and covers all topics within the framework. You will find a friendly companion with it.
  3. TypeScript Support. AdonisJs has first-class support for TypeScript. This means that TypeScript is not just a plugin, rather 100% of the core packages and addons are developed with TypeScript. AdonisJs has excellent intellisense support and you will be amazing with the confidence you will have while writing your code.
  4. Routing and Controllers. AdonisJs offers server-side routing of requests. Each route can be configured to call methods within controller classes. The methods have access to the context object which exposes the request, response, route, auth, bouncer, logger, params, session, view, and subdomain objects. So you can quickly return the JSON responses or render and return HTML view from controller methods. Moreso, with the Async Local Storage, you can access the same context in any file outside your controller or middleware.
  5. File Uploads Management. AdonisJs has built-in support for file uploads to the file storage or directly to storage providers such as Amazon S3 or Google Drive or Cloudinary.
  6. Server-side rendering. AdonisJs comes with the Edge templating engine which you can use to build server-side rendered applications instead of single-page applications.
  7. Request Validator. AdonisJs has a built-in Validator package for validating data sent from the frontend before they are saved to the database.
  8. Database & ORM. AdonisJs has the Lucid package for performing database operations. It includes a fluent ORM with support for hooks, query scopes, serialization, relationships, seeders, and factories.
  9. Middleware. One of the most beautiful features of AdonisJs is how easy it is to write and configure middlewares. You can use middlewares to intercept requests at the route definition, perform extra checks, and inject more data into the context object before the controller method is called.
  10. Authentication. AdonisJs comes with the auth package which provides different mechanisms for authentications within your application. It also includes social authentications.
  11. Security. AdonisJs comes with the shield package which provides protection against web vulnerabilities such as CSRF, XSS, and Content Sniffing for your server-rendered applications. Your can also enable CORS to protect your API server from being called outside authorised origins.
  12. Hashing and Encryption. AdonisJs has built-in support for encryption and hashing including URL signing. You do not have to install extra packages for this.
  13. Authorization. The bouncer package provides an authorization framework for AdonisJs. You can setup checks against an authenticated user and limit what resource or operations they have access to.
  14. The built-in Logger package can be used for application-wide logging.
  15. The asynchronous event emitter provides ability to setup and listen to events across the application.
  16. The mailer package is available for sending emails.
  17. The Redis package is available for performing asynchronous operations on the Redis server.
  18. Deployment. AdonisJs being a Nodejs framework can easily be deployed on VPS server via PM2 or to Heroku or Digital Ocean.

You will find details of all these in the documentation.

Now, you understand why I chose AdonisJs.

See you in the next lesson where we'll setup our API server with AdonisJs.