There was Rails, then Laravel and now Adonis js (part 2)
Tags: javascript, adonis, rails, laravel
Published: 2021-03-23 12:00:08

---
title: There was Rails, then Laravel and now Adonis js (part 2)
published: true
description: 
tags: javascript, adonis, rails, laravel
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2r7pwf06szmde50ryv93.png
series: AdonisLaravel
---
Follow me on Twitter: <a href="https://twitter.com/justericchapman?ref_src=twsrc%5Etfw" class="twitter-follow-button" data-show-count="false">Follow @justericchapman</a><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

<h2>Adonis = MVC Framework for Node</h2>
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.

<h2>Requirement</h2>
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:
```
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/)

<h2>Create a Laravel vs Adonis Project</h2>
In Laravel to create and launch a new web app we type in the terminal:
```
laravel new myapp
cd myapp
php artisan serve
```
![laravel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/trscejso0nxf4ef6kxw7.png)

In Adonis.js to create and launch a new web app we type in the terminal:
```
npm init adonis-ts-app myapp
cd myapp
node ace serve --watch
```
![adonis](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sgkj41h24ye5xc4fyc42.png)

<h2>Project folders structure</h2>
Here is Laravel folder structure:
![laravel folder structure](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sobhvpljj9l0jg8jwr1a.png)

Here is Adonis.js folder structure:
![adonis folder structure](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/grl6u8wg45umryi1uoc4.png)

Here a list of main folder location:
<table>
  <thead>
    <tr>
      <th></th>
      <th>Laravel</th>  
      <th>Adonis.js</th>  
   </tr>
  </thead>
  <tbody>
    <tr>
      <td>routes</td>
      <td>routes/web.php</td>
      <td>start/routes.ts</td>
    </tr>
    <tr>
      <td>controllers</td>
      <td>app/Http/Controllers</td>
      <td>app/Controllers</td>
    </tr>
   <tr>
      <td>models</td>
      <td>app/Models</td>
      <td>app/Models</td>
    </tr>
    <tr>
      <td>migrations</td>
      <td>database/migrations</td>
      <td>database/migrations</td>
    </tr>
    <tr>
      <td>views</td>
      <td>resources/views</td>
      <td>resources/views</td>
    </tr>
  </tbody>
</table>
As you can see both are very similar!

<h2>Project CLI commands</h2>
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:
<table>
  <thead>
    <tr>
      <th></th>
      <th>Laravel</th>  
      <th>Adonis.js</th>  
   </tr>
  </thead>
  <tbody>
    <tr>
      <td><small>create model</small></td>
      <td><small>php artisan make:model Post</small></td>
      <td><small>node ace make:model Post</small></td>
    </tr>
    <tr>
      <td><small>create controller</small></td>
      <td><small>php artisan make:controller Post</small></td>
      <td><small>node ace make:controller Post</small></td>
    </tr>
   <tr>
      <td><small>create migrations</small></td>
      <td><small>php artisan make:migration post</small></td>
      <td><small>node ace make:migration post</small></td>
    </tr>
    <tr>
      <td><small>Run migrations</small></td>
      <td><small>php artisan migrate</small></td>
      <td><small>node ace migration:run</small></td>
    </tr>
  </tbody>
</table>

<h2>Install Adonis database module</h2>
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
```


<h2>Conclusion</h2>
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: <a href="https://twitter.com/justericchapman?ref_src=twsrc%5Etfw" class="twitter-follow-button" data-show-count="false">Follow @justericchapman</a><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>