AdonisJs official Blog

NodeJs framework for Humans

Read this first

The Reddit Fire

Recently a thread on Reddit asking whether AdonisJs is ready for production and not? caught my attention towards the weird reasons shared by users on the thread.

One of the most popular ones was

Most of the packages are hand-written from scratch and that’s why the framework is not production ready.

Like seriously?


Before I really get into the specifics, I want to share the philosophy of the framework.

AdonisJs is not a toolset, it’s an experience. For example:

  • Android gives you a software and then all these companies, bundle that software into fucked up hardware.
  • Whereas Apple decided to ship the experience of using a mobile device, they don’t care, whether they created everything by hand or they outsourced it.

Now let’s dive into the criticisms.


The test runner

A common complaint is related to japa, the test runner used by AdonisJs to write and run tests. Before writing...

Continue reading →


Changing Route.url behavior

The Route.url method returns a fully qualified URL to a registered route. For example:

// register route
Route.get('user/:username', 'UserController.show')

// following returns - user/virk
Route.url('user/:username', { username: 'virk' })

// or resolve using controller.method name
Route.url('UserController.show', { username: 'virk' })

For a specific domain

Route.url method used to take a 3rd parameter called domain. Which resolves the URL but registered under a specific domain.

Route
  .get('post/:slug', 'PostController.show')
  .domain('blog.adonisjs.com')

// following returns - http://blog.adonisjs.com/post/adonis-101
Route.url(
  'PostController.show',
  { slug: 'adonis-101' },
  'blog.adonisjs.com'
)

In near future

Going forward the 3rd parameter needs to be an object over a string. The change is done in the favor of accepting more configuration options in the near future.

...

Continue reading →


Depreciating self reference inside config files

AdonisJs allows you to define reference to an existing value inside the config files. For example

config/app.js

module.exports = {
   appKey: Env.get('APP_KEY')
}

Now you can make use of the above value inside any other config file using the following syntax.

config/auth.js

module.exports = {
   jwt: {
     secret: 'self::app.appKey'
   }
}

In order to resolve self references, each Config.get call has to recursively parse the return value and make sure all references to self are resolved.

This behavior causes an unnecessary performance overhead, without any major gains.

adonis-framework@4.0.30 has marked this behavior as depreciated and will be removed in another minor release of the framework ( 4.1.0 ).

View →


Here you go - Adonis 4.0 ?

Version 4.0 of AdonisJs is officially out and not only it is ready to be used in production, but you can also invest your time to build long-term projects, and there are reasons behind such a strong voice.

  1. Javascript as a language has seen new changes almost every morning and being a pure Javascript framework; Adonis has to support all these features. Since significant parts of the language like async/await, proxies are fully implemented, we are not expecting any big changes forcing a re-write of the framework.

  2. After the dev release, I successfully got AdonisJs running in production inside Kayako ( the company I work for ). That means I use it every day at work, taking out more time to improve it and build tooling around the framework.

  3. I am happy to accept that we are a small community ( not as big as React ) but it is changing. Every morning I get at-least 10 new PR’s and a bunch of...

Continue reading →


Adonis 4.0 Dev Release

Adonis4.0 has been much-awaited release for AdonisJs so far. The framework is full of new and fresh ideas to make you even more productive.

The documentation for dev release is available at dev.adonisjs.com. The API is 100% final, so feel free to start new or upgrade your existing apps.

Npm organization and scope packages

Since npm orgs are now available to open source projects for free, it is the right time to move all packages to an organization and scope them with @adonisjs prefix. This way it is easier to spot the official packages from the community ones.

Speed improvements

Adonis4.0 is almost 4 times faster than the earlier versions of AdonisJs. Here are the benchmarks.

This has been possible due to the usage of async/await which is inherently faster than generators.

Also, the code for HTTP request/response lifecycle has been simplified too.

ES6 features

Javascript is...

Continue reading →


Curious Case Of Date Formats In Data Models

Every major release of AdonisJs gives me a chance to introduce breaking changes (for the good) and make sure AdonisJs addresses the majority of common use cases in development land.

This time I have been brainstorming about dateFormat defined on Lucid models, what purpose does it serves and how flexible is it with different use-cases.

Before we really dig into the implementation details, let’s see an example of how date format works as of now and what challenges it has.

class User extends Lucid {

  static get dateFormat () {
    return 'YYYY-MM-DD HH:mm:ss'
  }

}

Now every time you save a record to the database or fetch it from the database, the dates get formatted as per the defined format.

Challenges

There are handful of challenges with this approach

  1. What if I need a different format for saving the data and different format when displaying the data?
  2. What if different date...

Continue reading →


Contributing to AdonisJs

Quite often I am asked on how to contribute to AdonisJs and it is so important to have some clarity on same since contributors are the force behind any open source project.

This post gives an overview on how you can get started contributing to AdonisJs based upon your interests and skill level.

Feel free to reach me on Gitter or email me at virk@adonisjs.com about any specific questions or concerns you have. Always willing to help.

Documentation

AdonisJs docs are far better than most of the other open source projects, but they are not the best. Documentation is the area which needs lots of love and care to make them beginners friendly and document every possible use case.

If you enjoy writing technical documentation and wants to help AdonisJs grow, then feel free to clone adonisjs/docs repo and create a PR with your changes.

  1. Documentation is written using Asciidoctor and get...

Continue reading →


# Petit mais grand (AdonisJs 3.2.1)

I am about to step the paddle for the major release of Adonisjs version 4.0 (called dawn).

Dawn will be released with lots of exciting features including first class support for async/await, testing, tooling for deployment and bunch of ? features.

But It’s about the present

This post is about the features you can use today in Adonisjs. Today I have released v3.2.1 which is ideally a small release but has lot more to offer.

Lucid

Latest release of lucid ships with powerful features to filter data based upon relationships.

Fetch users with alteast one post

Let’s say we want to fetch all users who have contributed alteast one post.

const User = use('App/Model/User')

yield User.query().has('posts', '>=', 1).fetch()

The has method will filter out all records from the parent model, if child models doesn’t satisfy a rule.

Checkout official documentation for all available methods.

...

Continue reading →


Using Socket.Io with Adonis3.0

Since inbuilt support for web sockets is missing in AdonisJs, using socket.io with AdonisJs is extremely simple.

Setting Up Socket.Io

Using Existing Http connection is very common when starting a websocket server using socket.io. Let’s start by creating a socket.js file inside app/Http directory.

app/Http/socket.js

'use strict'

module.exports = function (server) {

  const io = use('socket.io')(server)

  io.on('connection', function (socket) {
    console.log('connection created >>>')
  })

}

This file exposes a function which accepts the HTTP server instance and using that instance you can create a web socket connection. Now you can approach socket.io the way you want.

Next you need to import this file inside bootstrap/http.js file. Just before the Server.listen import this file.

bootstrap/http.js


use('App/Http/socket')(Server.getInstance())

Server.listen(Env.get('HOST'),
...

Continue reading →


AdonisJs 3.0 Release

The shiny new release of AdonisJs is out today (26th, June 2016). It’s more than just another new version. We have taken a bigger step towards making AdonisJs one of the best and stable framework in the community.

3.0 dev release stayed in beta for over 2 months, which helped in finding last time issues and fix the core of the framework for better tomorrow. Not only the code even new documentation is improved and tailored to make every skill level programmer feel comfortable.

Let’s talk about some notable features which are going to make your development experience smoother.

Request Collections

Request collections solve the most common problem of dealing with the creation of multiple records inside a single HTML form. Make sure to check out this video to learn more about it.

Data Driven Architecture

AdonisJs data models (Lucid) is the implementation of Active Record pattern. Not...

Continue reading →