This series was written while AdonisJS 5 was still in preview. AdonisJS 5 has since been fully released and with it, we have a new series to account for the changes.
Today we'll be starting our first Let's Learn. In this series we'll do deep dives into particular topics, covering all the core concepts involved. In this Let's Learn, we'll be covering Adonis 5. Adonis 5 is a type-safe and extensive NodeJS framework.
Out of the box, Adonis includes routing, form validation, the Edge template engine, JSON serializers for your APIs, its active-record ORM called Lucid, migrations, seeds, factories, multi-driver authentication, security, and more.
Adonis 5 Is Still In Preview
Adonis 5 is still in preview, however, as things progress toward the final release of Adonis 5 I will update this series accordingly. If you'd like to learn more on your own about Adonis 5, you can find more information on their site at: https://preview.adonisjs.com/.
There are a couple of prerequisites you'll need to meet in order to progress with Adonis 5 and this series. You'll need NodeJS version
12.0.0 or later and NPM version
6.0.0 or later. You can check your versions in your terminal by running:
$ node -v # v14.15.1 $ npm -v # v6.14.8Copied!
Upgrading Using NVM
If you're using Node Version Manager (NVM) like I am, you can upgrade your node version to the latest release by running:
$ nvm install node # Now using node v15.3.0 (npm v7.0.14)Copied!
This will install the latest release for both NodeJS and NPM.
To set this version of NodeJS and NPM as your default versions you can run the below.
$ nvm alias default 15.3.0 # replacing 15.3.0 with whatever version of node was installed for youCopied!
Upgrading Using Installer
If you're not using NVM, you can upgrade both NodeJS and NPM by downloading and running the latest Node installer from https://www.nodejs.org.
Just download the latest LTS or Current version, run the installer, and progress through the steps.
Creating Our Project
Now that we meet the requirements for Adonis 5, we're ready to create our application! To do this we can run the following in our terminal. Note that
adonis5 below is where the project name goes, feel free to name your project whatever.
$ npm init adonis-ts-app adonis5Copied!
For the purposes of this series, when we're referencing our project path you'll see
Next, we'll be asked a couple of questions.
Select the project structure: Web Application
Web Applications will include the Edge template engine, the sessions module, static asset support, and CSRF protection.
API Servers will be more suited for an API application including things like CORS and JSON content negotiation.
For this series, we'll be building a Web Application, so be sure to select Web Application.
Enter the project name: adonis5
Feel free to enter whatever here.
Setup eslint? false
Again, your call here too. eslint will enforce codebase standards if you decide to set it up.
Congratulations! Your first Adonis 5 application has now been created. Now we can go ahead and change into our new project's directory.
$ cd adonis5Copied!
Then we can start the local server by running:
$ node ace serve --watchCopied!
Note that by adding
--watch we're telling our server to watch for changes. You can alternatively run this command using NPM by running:
$ npm run devCopied!
Now that our server is running we can open up our new project at the specified server port, the default port is
Once you open your application in the browser you should see a "It Works!" welcome page.
In the next lesson, we'll discuss the project's structure and the basics of routing within our Adonis 5 application.