Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Contents

What AdonisJS is

AdonisJS is a framework for server-side web applications on Node.js and TypeScript. It already contains everything a site needs: routes, controllers, templates, database access, validation, user login. If you know Laravel, much will look familiar: AdonisJS is built on the same ideas, only in JavaScript.

The course targets AdonisJS 6. The code is TypeScript with ES modules (import and export), which you have already met in the JavaScript tutorial.

How it differs from Express

Express gives you only routes and middleware, and you assemble the rest from separate libraries. AdonisJS is a "batteries included" framework: the parts are chosen in advance, configured and work together.

TaskWhat AdonisJS uses
Routes and controllersthe built-in router
HTML pagesthe Edge template engine
Databasethe Lucid ORM
Form data validationthe VineJS library
Login and permissionsthe @adonisjs/auth and @adonisjs/bouncer packages
Terminal commandsthe Ace console
TestsJapa

An ORM (Object-Relational Mapping) is a way to work with database tables through classes and objects instead of SQL strings.

What you need

You need Node.js 20.6 or newer and npm, which comes with it. Check the versions in the terminal:

node -v
npm -v

If the first command prints a version below 20.6, update Node.js from nodejs.org.

The path of a request

Every request in an AdonisJS application goes through the same steps:

  1. The browser requests an address, for example /posts.
  2. The router finds the route for this address in start/routes.ts.
  3. The request passes through middleware — checks like "is the user logged in".
  4. The route calls a controller method.
  5. The controller gets data through a model and passes it to an Edge template.
  6. The finished HTML page goes back to the browser.

Each step has its own lesson.

The course project

One project runs through the whole course — a blog. It will have posts, comments on them and users who sign up, log in and write posts. By the end of the course the blog will also have cover uploads, emails, a JSON API and tests.

Common mistake

Many examples on the internet are written for AdonisJS 5: they use Route.get(...) with a capital letter and imports like @ioc:Adonis/Core/Route. Such code does not work in version 6. Look for documentation and examples for version 6 — their imports start with @adonisjs/... or #, for example import router from '@adonisjs/core/services/router'.

Thanks for reading!

Donate to the site — we work hard for you.