Adonis is very sensitive and node version mixup. You will literally lose access to all node ace commands! So be very careful with this!

First make sure that node version is 24.x. Then create desired folder and enter it. Here we will use adonis-test as folder name

mkdir adonis-test && cd adonis-test

Then type the init command to start setup –

npm init adonisjs@latest . -- --db=mysql --kit=api

On setup screen, select Access Token for authentication guard and let setup continue.

After setup is done run npm run dev and go to http://localhost:3333/ if you see the test { “hello” : “world”} JSON, its ready to run

We are then going to do a GIT init and first commit. Just in case anything goes wrong and we need to revert. This thing is damn troublesome!

Use this as a starter .env file content. Of course, set proper values for database, generate key, etc.

TZ=UTC

PORT=3333
HOST=localhost

LOG_LEVEL=info

# use node ace generate:key to generate key ...
APP_KEY=YOU_APP_KEY

# node environment
NODE_ENV=development

# Database info ...
DB_HOST=localhost
DB_PORT=3306
DB_USER=YOUR_DB_USER
DB_PASSWORD=YOUR_DB_PASS
DB_DATABASE=YOUR_DB_NAME
DB_SOCKET_PATH=SOCKET_PATH_IF_USE_ANY

If you are using mysql socket (like working with MAMP on Mac OS), be sure to add socket path in config/database.ts like this –

import env from '#start/env'
import { defineConfig } from '@adonisjs/lucid'

const dbConfig = defineConfig({
  connection: 'mysql',
  connections: {
    mysql: {
      client: 'mysql2',
      connection: {
        host: env.get('DB_HOST'),
        port: env.get('DB_PORT'),
        user: env.get('DB_USER'),
        password: env.get('DB_PASSWORD'),
        database: env.get('DB_DATABASE'),
        socketPath: env.get('DB_SOCKET_PATH'),
      },
      migrations: {
        naturalSort: true,
        paths: ['database/migrations'],
      },
    },
  },
})

export default dbConfig

Otherwise, adonis wont connect to database, and you might waste a lot of time scratching your head.