AdonisJs official Blog

by Harminder Virk

NodeJs framework for Humans

Read this first

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 →


Adonis 3.0 dev release

Adonis 3.0 is going to be the most stable release so far. In past few months, we have gathered plenty of feedback, solved a handful of issues and progressively made Adonis the most practical framework in the community.

The newer version is going to have breaking changes and this dev release is a sneak peek of same. If you are planning to start a new project, consider using the dev release as it is going to be the future.

 Setting up dev project

You can make use of adonis-cli to setup the dev project, but make sure to pass the --dev flag.

adonis new yardstick --dev

 What’s new?

Lots of new features have been added to the framework that I will be talking about, also trello board can be used as a reference for same https://trello.com/b/yzpqCgdl/adonis-for-humans.

 Model Hooks

Model hooks have been introduced to keep your code DRY by attaching hooks to your models, which are called on

Continue reading →


Hello Adonis - Journey to the future

Official Website http://adonisjs.com

Being a JavaScript developer, I adopted Node Js in its early days and no matter what, it has been a joyful journey.

Npm being the largest package manager (http://www.modulecounts.com) offers a bunch of tools to improve your everyday workflow. I myself have used nearly every popular package until I reached the point of saturation.

This saturation point is the real factor, I decided to write Adonis Js and approached things differently from all other libraries and frameworks offered by the community. This post is not a comparison to any existing frameworks, in fact, an opportunity to share the broader view of Adonis Js.

I generally receive questions on why to use Adonis Js over Sails Js or Express/Koa.

Express/Koa are thin wrappers over the Node Http server, which may be best suited for certain applications but the majority of applications requires

Continue reading →


Basic Authentication With AdonisJs

With the release of Adonis 2.0, i have received lot of queries on how to authenticate requests in Adonis.

Adonis is an MVC framework for NodeJs, it borrows the concept of Service providers from popular PHP Framework Laravel.

I personally divides authentications into two different parts. First the stateful authentication where we save cookies into browser and use it to find login state for a given user. Other one is the stateless authentication, where each request is authenticated.

The later one is quite popular with RestFul API’s, where we authenticate every API request and a common way to achieve that is to make use of Basic Auth.

In this article, i will share the process of writing a middleware and then authenticating routes with the help of basicauth middleware. Also the final code is available on https://github.com/thetutlage/adonis-auth-tutorial.

 Creating a new application

Continue reading →