Roadmap to building your first AdonisJs web application
September 11, 20201 min readAdonisJs is a Node.js web framework with a breath of fresh air and a drizzle of elegant syntax on top of it. It helps you write test-driven web applications easily. Learning Adonisjs as Nodejs/Laravel developer is quite easy because the flow is very similar.
Adonisjs core features
- Routing
- Middleware
- Controllers
- Request and Validators
- Response
- View
- Session
- Logger
- Events
- File upload
- Mails
- Database query and Lucid ORM
- Migration, seeders, and factories.
- Built-in JWT (JavaScript Web Token).
- CORS.
- CSRF Protection.
- TDD. (Feature and Unit test).
- Websocket.
Basic requirements
- Install Nodejs on your machine
- npm support
- Git bash
Installation of Adonisjs
Installation via CLI
AdonisJs CLI is a command-line tool to help you install AdonisJs.
Install it globally via npm like so:
> npm i -g @adonisjs/cli
For example, to create a new application called blog, simply:
> adonis new blog
Adonis also comes with a feature to create an API only application just like Express/Lumen
For example, to create a new application called blog, simply:
> adonis new blog --api-only
After crafting your application you can cd into the blog, to start your application in a development environment.
> npm install
> adonis serve --dev
It's serving your adonis application based on the port defined in your .env
Basic commands to use in your Adonis application
Start server
> adonis serve --dev
New application
> adonis new blog
> adonis new blog --api-only
> adonis new blog --slim
Make controller
> adonis make:controller User
Make model
> adonis make:model User
Make migration
> adonis make:migration User
Make validator
> adonis make:validator LoginRequest
Make command
> adonis make:command SetupAdmin
Make middleware
> adonis make:middleware isAdmin
Make exceptions
> adonis make:exceptions PaymentError
Make test
> adonis make:test AuthTest
Directory structure
- app: controllers, middleware, commands, models, exceptions, validator. etc.
- config: it holds different configuration files.
- database: migration, factory, seeder etc.
- public: it is used to serve the static assets of the site over HTTP.
- resources: it holds the views etc.
- start: it holds the route.js, kernel.js, app.js.
- test: it holds the feature and unit test
- ace
- package.json
- server.js
You can also consult their documentation for more info: https://adonisjs.com/docs/4.1/installation