Follow me on Twitter: Follow @justericchapman
Adonis = MVC Framework for Node
Recently, I stumbled across a framework that had been around for quite some time but for some reasons had gone under my radar. This framework is Adonis.js
What is Adonis? In summary, this is the Node.js version of Laravel. It is a framework that contrasts with other Node.js frameworks. Like Laravel, Adonis has for mission the happiness of the developer and also as mandate to provide all the necessary tools to carry out a project from A to Z.
Being an MVC framework just like Laravel, the learning curve is much shorter.
In part 1, I present you code sample of both framework to show you the similarities. Today we will get a notch further and create a first Adonis project and will compare Adonis commands with Laravel commands.
To create a Adonis project the only requirement is to have Node.js install on your machine. Since Node is use a lot in dev world, good change you already have it.
Type this command in the terminal to check your installed Node version:
If version >= 12.0.0 you ar ok. If not go to nodejs.org and install the last version. (https://nodejs.org/en/download/)
Create a Laravel vs Adonis Project
In Laravel to create and launch a new web app we type in the terminal:
laravel new myapp
php artisan serve
In Adonis.js to create and launch a new web app we type in the terminal:
npm init adonis-ts-app myapp
node ace serve --watch
Project folders structure
Here a list of main folder location:
As you can see both are very similar!
Project CLI commands
In Laravel (and in Adonis) to create project element we can use CLI. For example if we want to create a migrations there is a command for that. Same for models and controller.
Here a list of main CLI commands:
|php artisan make:model Post
|node ace make:model Post
|php artisan make:controller Post
|node ace make:controller Post
|php artisan make:migration post
|node ace make:migration post
|php artisan migrate
|node ace migration:run
Install Adonis database module
In Laravel all module are include with default install. In Adonis.js only the core module is install by default. For example, to use a database we have to install the database module:
Installing that module is easy. Here the CLI commands to install and run first config:
npm i @adonisjs/lucid@alpha
node ace invoke @ajonisjs/lucid
That's it for today. Stay tune because I will post many more articles on Adonis.js in near future.
You can follow me on Twitter: Follow @justericchapman