### Install Dependencies Source: https://github.com/adonisjs/v6-docs/blob/main/README.md Command to install project dependencies after cloning the docs boilerplate. ```sh cd \nnpm i ``` -------------------------------- ### Install Basic Auth Guard Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/authentication/introduction.md Use the AdonisJS CLI to add the authentication package with the basic_auth guard. This command automates the setup process. ```bash node ace add @adonisjs/auth --guard=basic_auth ``` -------------------------------- ### Install Ally Package and Providers Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/authentication/social_authentication.md Install the core @adonisjs/ally package and optionally specify providers like github and google during installation. ```sh node ace add @adonisjs/ally # Define providers as CLI flags node ace add @adonisjs/ally --providers=github --providers=google ``` -------------------------------- ### Start Directory Structure Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/folder_structure.md Outlines the files typically placed in the 'start' directory for application bootstrapping. This includes environment configuration, kernel, routes, and event listeners. ```bash ├── start │ ├── env.ts │ ├── kernel.ts │ ├── routes.ts │ ├── validator.ts │ ├── events.ts ``` -------------------------------- ### Install Transmit Client Package Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/digging_deeper/transmit.md Install the client-side package to enable listening for events in the browser. ```sh npm install @adonisjs/transmit-client ``` -------------------------------- ### Navigate and Install Dependencies Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/concepts/typescript_build_process.md After building, change into the `./build` directory and install only production dependencies using `npm ci --omit=dev` to minimize the deployment size. ```bash cd build # Install production dependencies npm ci --omit=dev ``` -------------------------------- ### Install Package with Configuration Flags Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/references/commands.md Installs a package and passes configuration flags directly to the add command. Unknown flags are passed down to the configure command. ```bash node ace add @adonisjs/lucid --db=sqlite ``` -------------------------------- ### Run Redis Commands Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/database/redis.md Execute Redis commands using the 'redis' service. Import the service and use its methods, which mirror the ioredis API. This example sets and gets a value. ```typescript import redis from '@adonisjs/redis/services/main' await redis.set('username', 'virk') const username = await redis.get('username') ``` -------------------------------- ### Install Playwright and Japa Browser Client Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/testing/browser_tests.md Install the necessary packages for browser testing using npm. ```sh npm i -D playwright @japa/browser-client ``` -------------------------------- ### Install VineJS Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/basics/validation.md Install and configure VineJS using the AdonisJS CLI. This command registers the necessary service provider. ```sh node ace add vinejs ``` -------------------------------- ### Install @adonisjs/cache package Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/digging_deeper/cache.md Run this command to install the cache package and register its service provider. ```sh node ace add @adonisjs/cache ``` -------------------------------- ### Install @adonisjs/limiter package Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/security/rate_limiting.md Install and configure the @adonisjs/limiter package using the ace command. This command handles package installation, service provider registration, and configuration file creation. ```sh node ace add @adonisjs/limiter ``` -------------------------------- ### Install JWT Package Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/authentication/custom_auth_guard.md Installs the 'jsonwebtoken' package and its types for generating JWT tokens. ```sh npm i jsonwebtoken @types/jsonwebtoken ``` -------------------------------- ### Install @adonisjs/otel Package Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/digging_deeper/open_telemetry.md Install the OpenTelemetry integration package for AdonisJS using the Ace CLI. ```sh node ace add @adonisjs/otel ``` -------------------------------- ### Configure command to start the application Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/ace/creating_commands.md Set `startApp: true` in `options` if your command requires the application to be booted. ```typescript import { BaseCommand } from '@adonisjs/core/ace' import { CommandOptions } from '@adonisjs/core/types/ace' export default class GreetCommand extends BaseCommand { // highlight-start static options: CommandOptions = { startApp: true } // highlight-end } ``` -------------------------------- ### Install Nodemailer and Postmark Transport Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/digging_deeper/mail.md Install the necessary packages for creating a custom Postmark email transport. ```sh npm i nodemailer nodemailer-postmark-transport ``` -------------------------------- ### Install Package with Dev Flag Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/references/commands.md Installs a package as a development dependency. Use this for packages that are only needed during development. ```bash node ace add my-dev-package --dev ``` -------------------------------- ### Greet command implementation Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/testing/console_tests.md Example implementation of a basic 'Greet' Ace command that logs a message. ```typescript import { BaseCommand } from '@adonisjs/core/ace' import { CommandOptions } from '@adonisjs/core/types/ace' export default class Greet extends BaseCommand { static commandName = 'greet' static description = 'Greet a username by name' static options: CommandOptions = {} async run() { this.logger.info('Hello world from "Greet"') } } ``` -------------------------------- ### Install Prettier Configuration Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/concepts/tooling_config.md Install the @adonisjs/prettier-config package and prettier. This sets up the base configuration for auto-formatting source code. ```sh npm i -D @adonisjs/prettier-config # Make sure also to install prettier npm i -D prettier ``` -------------------------------- ### Install ESLint Configuration Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/concepts/tooling_config.md Install the @adonisjs/eslint-config package and eslint. This sets up the base configuration for applying linting rules. ```sh npm i -D @adonisjs/eslint-config # Make sure also to install eslint npm i -D eslint ``` -------------------------------- ### Start Development Server with Watch Mode Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/concepts/typescript_build_process.md Use the `ace serve --watch` command to start the development server. This command includes a file watcher that restarts the server on changes and integrates with frontend asset bundlers like Vite. ```sh node ace serve --watch ``` -------------------------------- ### Conditional Logic in start Method based on Environment Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/concepts/service_providers.md Implement environment-specific logic within the `start` method. This method is called after `boot` and before `ready`, allowing for actions needed by the `ready` hook. ```typescript export default class AppProvider { async start() { if (this.app.getEnvironment() === 'web') { } if (this.app.getEnvironment() === 'console') { } if (this.app.getEnvironment() === 'test') { } if (this.app.getEnvironment() === 'repl') { } } } ``` -------------------------------- ### Install Drive Package Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/digging_deeper/drive.md Installs the @adonisjs/drive package and registers its service provider. It also creates the configuration file and sets up environment variables. ```sh node ace add @adonisjs/drive ``` -------------------------------- ### Install Lucid ORM and Create Model Source: https://context7.com/adonisjs/v6-docs/llms.txt Install the Lucid ORM package and generate a new model with its migration file. ```sh node ace add @adonisjs/lucid ``` ```sh node ace make:model Post -m # creates model + migration ``` ```sh node ace migration:run ``` -------------------------------- ### Install @adonisjs/static Package Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/basics/static_file_server.md Install the @adonisjs/static package using the ace command. This command also handles initial configuration steps. ```sh node ace add @adonisjs/static ``` -------------------------------- ### Install and Create EdgeJS View Source: https://context7.com/adonisjs/v6-docs/llms.txt Install the EdgeJS templating engine using `node ace add edge` and create a new view file using `node ace make:view`. ```sh node ace add edge node ace make:view pages/home ``` -------------------------------- ### Basic Browser Test Example Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/testing/browser_tests.md An example test that visits the home page and asserts the presence of specific text. Requires the 'visit' helper provided by the browser client plugin. ```typescript // title: tests/browser/pages/home.spec.ts import { test } from '@japa/runner' test.group('Home page', () => { test('see welcome message', async ({ visit }) => { const page = await visit('/') await page.assertTextContains('body', 'It works!') }) }) ``` -------------------------------- ### Greet command with table output Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/testing/console_tests.md Example implementation of a 'Greet' Ace command that renders a table with user data. ```typescript async run() { const table = this.ui.table() table.head(['Name', 'Email']) table.row(['Harminder Virk', 'virk@adonisjs.com']) table.row(['Romain Lanz', 'romain@adonisjs.com']) table.row(['Julien-R44', 'julien@adonisjs.com']) table.row(['Michaël Zasso', 'targos@adonisjs.com']) table.render() } ``` -------------------------------- ### Get Path to Start Directory Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/concepts/application.md Retrieve the absolute path to a file within the project's start directory using app.startPath. If no file is specified, it returns the path to the start directory itself. ```typescript app.startPath('routes.ts') // /project_root/start/routes.ts app.startPath() // /project_root/start ``` -------------------------------- ### Download Starter Kit with Specific Tag Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/installation.md Download a starter kit from a Git repository and checkout a specific tag. Append '#tag_name' to the repository identifier. ```sh npm init adonisjs@latest -- -K="user/repo#v2.1.0" ``` -------------------------------- ### Start AdonisJS REPL Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/digging_deeper/repl.md Initiate an AdonisJS REPL session from your project's root directory. ```sh node ace repl ``` -------------------------------- ### Install @adonisjs/i18n Package Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/digging_deeper/i18n.md Install and configure the package using the `ace add` command. This command registers the service provider, creates configuration files, and sets up necessary middleware. ```sh node ace add @adonisjs/i18n ``` -------------------------------- ### Download Starter Kit from Bitbucket Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/installation.md Download a custom starter kit from a Bitbucket repository. Use the 'bitbucket:' prefix followed by the username and repository name. ```sh npm init adonisjs@latest -- -K="bitbucket:user/repo" ``` -------------------------------- ### Basic HTTP GET Request Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/testing/http_tests.md Make a GET request to an endpoint and assert the status code and response body. This is a fundamental example of testing an API endpoint. ```ts import { test } from '@japa/runner' test.group('Users list', () => { test('get a list of users', async ({ client }) => { const response = await client.get('/users') response.assertStatus(200) response.assertBody({ data: [ { id: 1, email: 'foo@bar.com', } ] }) }) }) ``` -------------------------------- ### Read/Write Encrypted and Plain Cookies Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/testing/browser_tests.md Provides examples for setting and getting both encrypted and plain cookies using the browser context. ```typescript // Write await browserContext.setEncryptedCookie('username', 'virk') await browserContext.setPlainCookie('username', 'virk') // Read await browserContext.getEncryptedCookie('cartTotal') await browserContext.getPlainCookie('cartTotal') ``` -------------------------------- ### Run Development Server Source: https://github.com/adonisjs/v6-docs/blob/main/README.md Command to start the development server for the AdonisJS docs boilerplate. ```sh npm run dev ``` -------------------------------- ### Define command help text Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/ace/creating_commands.md Provide a longer description or usage examples using the `help` property. ```typescript export default class GreetCommand extends BaseCommand { static help = [ 'The greet command is used to greet a user by name', '', 'You can also send flowers to a user, if they have an updated address', '{{ binaryName }} greet --send-flowers', ] } ``` -------------------------------- ### Download Starter Kit from GitHub Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/installation.md Download a custom starter kit from a GitHub repository. Replace 'github_user/repo' with the actual GitHub username and repository name. ```sh npm init adonisjs@latest -- -K="github_user/repo" ``` -------------------------------- ### Run Production Server Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/concepts/typescript_build_process.md Once dependencies are installed in the build directory, start your AdonisJS application using the compiled JavaScript server file. ```bash # Run server node bin/server.js ``` -------------------------------- ### Install @adonisjs/session Package Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/basics/session.md Install and configure the session package using the AdonisJS CLI. This command also registers the necessary service provider and middleware. ```sh node ace add @adonisjs/session ``` -------------------------------- ### Download Starter Kit from GitLab Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/installation.md Download a custom starter kit from a GitLab repository. Use the 'gitlab:' prefix followed by the username and repository name. ```sh npm init adonisjs@latest -- -K="gitlab:user/repo" ``` -------------------------------- ### Create Slim Starter Kit with MySQL Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/installation.md Initialize a minimal AdonisJS project with the slim starter kit and configure MySQL as the database dialect. ```sh npm init adonisjs@latest -- -K=slim --db=mysql ``` -------------------------------- ### SSR Allowlist with Dynamic Page Filtering Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/views-and-templates/inertia.md Dynamically determines which pages to server-side render by providing a function to the `pages` prop in `config/inertia.ts`. This example excludes pages starting with 'admin'. ```typescript import { defineConfig } from '@adonisjs/inertia' export default defineConfig({ ssr: { enabled: true, pages: (ctx, page) => !page.startsWith('admin') } }) ``` -------------------------------- ### Create Web Starter Kit with MySQL Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/installation.md Use this command to initialize a new AdonisJS project with the web starter kit and configure MySQL as the database dialect. ```sh npm init adonisjs@latest -- -K=web --db=mysql ``` -------------------------------- ### Pass Node.js Command Line Arguments to Child Process Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/concepts/typescript_build_process.md When starting the development server, you can pass Node.js command line arguments to the child process by defining them before the `ace` command. This example shows how to disable warnings and enable the inspector. ```sh node ace --no-warnings --inspect serve --watch ``` -------------------------------- ### Download Starter Kit with Specific Branch Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/installation.md Download a starter kit from a Git repository and checkout a specific branch. Append '#branch_name' to the repository identifier. ```sh npm init adonisjs@latest -- -K="user/repo#develop" ``` -------------------------------- ### Create API Starter Kit with MySQL Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/installation.md Initialize a new AdonisJS project with the API starter kit and configure MySQL as the database dialect. ```sh npm init adonisjs@latest -- -K=api --db=mysql ``` -------------------------------- ### Install @adonisjs/cors Package Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/security/cors.md Install the CORS package and configure it in your AdonisJS application. This command handles package installation, service provider registration, configuration file creation, and middleware registration. ```sh node ace add @adonisjs/cors ``` -------------------------------- ### Install @adonisjs/bouncer Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/security/authorization.md Install and configure the @adonisjs/bouncer package using the Ace CLI. ```sh node ace add @adonisjs/bouncer ``` -------------------------------- ### Create Slim Starter Kit Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/installation.md Initialize a minimal AdonisJS project with only the core framework and default folder structure, suitable for minimalists. ```sh npm init adonisjs@latest -- -K=slim ``` -------------------------------- ### Config Directory Structure Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/folder_structure.md Holds runtime configuration files for the application and installed packages. ```bash ├── config │ ├── app.ts │ ├── bodyparser.ts │ ├── cors.ts │ ├── database.ts │ ├── drive.ts │ ├── hash.ts │ ├── logger.ts │ ├── session.ts │ ├── static.ts ``` -------------------------------- ### Install Auth with Session Guard Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/authentication/introduction.md Configure the auth system with the session guard for server-rendered applications or APIs on the same domain. ```sh node ace add @adonisjs/auth --guard=session ``` -------------------------------- ### Create AdonisJS Project with Web Starter Kit Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/installation.md Initialize a new AdonisJS project specifically using the web starter kit. ```sh npm init adonisjs@latest -- -K=web ``` -------------------------------- ### Install Edge.js Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/views-and-templates/edgejs.md Install the Edge.js package and configure it within your AdonisJS application. ```sh node ace add edge ``` -------------------------------- ### Setup Ace UI mode for testing logs Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/testing/console_tests.md Use 'each.setup' hook to switch Ace UI to 'raw' mode for capturing logs and revert to 'normal' mode afterwards. ```typescript group.each.setup(() => { ace.ui.switchMode('raw') return () => ace.ui.switchMode('normal') }) ``` -------------------------------- ### Create API Starter Kit with Token Authentication Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/installation.md Initialize a new AdonisJS project with the API starter kit and configure it to use token-based authentication instead of session-based authentication. ```sh npm init adonisjs@latest -- -K=api --auth-guard=access_tokens ``` -------------------------------- ### Create a unit test for the Greet command Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/testing/console_tests.md Generate a unit test file for the 'greet' command using 'ace make:test'. ```bash node ace make:test commands/greet --suite=unit # DONE: create tests/unit/commands/greet.spec.ts ``` -------------------------------- ### Install Bcrypt Driver Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/security/hashing.md Install the bcrypt npm package to use it with the AdonisJS hash service. ```sh npm i bcrypt ``` -------------------------------- ### List Available Helper Methods in REPL Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/digging_deeper/repl.md Execute the `.ls` command in the REPL to display a list of all available global helper methods and their descriptions. ```sh > (js) .ls ``` -------------------------------- ### Report Sample for RedisMemoryUsageCheck Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/digging_deeper/health_checks.md An example report from the `RedisMemoryUsageCheck`, showing current memory usage and thresholds. ```json { "name": "Redis memory consumption health check (main)", "isCached": false, "message": "Redis memory usage is 1.06MB, which is under the defined thresholds", "status": "ok", "finishedAt": "2024-06-22T05:36:32.524Z", "meta": { "connection": { "name": "main", "status": "ready" }, "memoryInBytes": { "used": 1109616, "warningThreshold": 104857600, "failureThreshold": 125829120 } } } ``` -------------------------------- ### Get Help for a Specific Command Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/ace/introduction.md Display help information for a single command by appending the --help flag. ```sh node ace make:controller --help ``` -------------------------------- ### Download Private Repo using Git+SSH Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/installation.md Download a private starter kit from a Git repository using Git+SSH authentication. This requires SSH keys to be set up correctly. ```sh npm init adonisjs@latest -- -K="user/repo" --mode=git ``` -------------------------------- ### Create a new controller Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/basics/controllers.md Use the `make:controller` command to scaffold a new controller file. ```sh node ace make:controller users ``` -------------------------------- ### Install Mail Package Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/digging_deeper/mail.md Install the @adonisjs/mail package and optionally pre-define transports using the ace command. ```sh node ace add @adonisjs/mail # Pre-define transports to use via CLI flag node ace add @adonisjs/mail --transports=resend --transports=smtp ``` -------------------------------- ### Create Inertia Starter Kit with React and SSR Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/installation.md Initialize an AdonisJS project with the Inertia starter kit, specifically configuring it for React with server-side rendering enabled. ```sh npm init adonisjs@latest -- -K=inertia --adapter=react --ssr ``` -------------------------------- ### Create a Welcome View Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/views-and-templates/edgejs.md Generate a new Edge.js view file using the `ace make:view` command. ```sh node ace make:view welcome ``` -------------------------------- ### Configure Installed Package Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/references/commands.md Configures a package after it has been installed. This command accepts the package name as the first argument. ```bash node ace configure @adonisjs/lucid ``` -------------------------------- ### Create API Starter Kit Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/installation.md Initialize a new AdonisJS project tailored for JSON API servers. This kit is a trimmed-down version of the web starter kit. ```sh npm init adonisjs@latest -- -K=api ``` -------------------------------- ### Install Argon2 for Hashing Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/security/hashing.md Install the `argon2` npm package to use the Argon2 hashing algorithm with AdonisJS. ```bash npm i argon2 ``` -------------------------------- ### Lazy Import Scrypt Driver with Config Provider Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/concepts/config_providers.md This example demonstrates how to use a config provider with a dynamic import for the Scrypt driver. This is recommended for async providers to ensure the driver is only loaded when needed. ```typescript import { configProvider } from '@adonisjs/core' export default { default: 'scrypt', list: { scrypt: configProvider.create(async (app) => { const { Scrypt } = await import('@adonisjs/core/hash/drivers/scrypt') const emitter = await app.container.make('emitter') return () => new Scrypt({ cost: 16384, blockSize: 8, parallelization: 1, maxMemory: 33554432, }, emitter) }) } } ``` -------------------------------- ### Install hot-hook Package Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/concepts/hmr.md Install the `hot-hook` npm package as a development dependency to enable HMR functionality. ```sh npm i -D hot-hook ``` -------------------------------- ### Install MJML Package Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/digging_deeper/mail.md Install the MJML package using npm to enable MJML markup for email creation. ```bash npm i mjml ``` -------------------------------- ### Configure Edge.js with Plugins and Globals Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/views-and-templates/edgejs.md Example of a preload file (`start/view.ts`) demonstrating how to register the `edge-iconify` plugin and define a global `appUrl` variable. ```typescript // title: start/view.ts import edge from 'edge.js' import env from '#start/env' import { edgeIconify } from 'edge-iconify' /** * Register a plugin */ edge.use(edgeIconify) /** * Define a global property */ edge.global('appUrl', env.get('APP_URL')) ``` -------------------------------- ### Create Inertia Starter Kit Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/installation.md Initialize a new AdonisJS project for building server-driven single-page applications using Inertia.js. This command sets up the basic Inertia adapter. ```sh npm init adonisjs@latest -- -K=inertia ``` -------------------------------- ### Install TypeScript Configuration Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/concepts/tooling_config.md Install the @adonisjs/tsconfig package and its peer dependencies. This sets up the base configuration for TypeScript projects. ```sh npm i -D @adonisjs/tsconfig # Make sure also to install the following packages npm i -D typescript ts-node-maintained @swc/core ``` -------------------------------- ### Create Test File Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/references/commands.md Generates a new test file. Use the --suite flag to define the test suite. Otherwise, a prompt will appear. ```bash node ace make:test --suite=unit ``` -------------------------------- ### Create AdonisJS Project with PostgreSQL and API Kit Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/installation.md Initialize a new AdonisJS project with PostgreSQL as the database and the API starter kit. ```sh npm init adonisjs@latest hello-world -- --db=postgres --kit=api ``` -------------------------------- ### Install @adonisjs/mail with SMTP and Resend transports Source: https://context7.com/adonisjs/v6-docs/llms.txt Install the mail package and specify the desired transports using the ace command. ```sh node ace add @adonisjs/mail --transports=smtp --transports=resend ``` -------------------------------- ### Get Redis Connection Instance Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/database/redis.md Get a specific Redis connection instance by its name. The connection is cached for the lifetime of the process. ```typescript import redis from '@adonisjs/redis/services/main' // highlight-start // Get connection instance const redisMain = redis.connection('main') // highlight-end await redisMain.set('username', 'virk') const username = await redisMain.get('username') ``` -------------------------------- ### Install Inertia Package Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/views-and-templates/inertia.md Install the `@adonisjs/inertia` package using npm. This command adds the necessary package to your project's dependencies. ```sh // title: npm npm i @adonisjs/inertia ``` -------------------------------- ### Start Application for Console Commands Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/concepts/application_lifecycle.md When creating a console command, set `static options = { startApp: true }` to ensure the application is booted and ready before the command's `run` method is executed. This makes `this.app.isReady` true within the command. ```typescript import { BaseCommand } from '@adonisjs/core/ace' export default class GreetCommand extends BaseCommand { static options = { startApp: true } async run() { console.log(this.app.isReady) // true } } ``` -------------------------------- ### Install Lucid ORM Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/database/lucid.md Install Lucid ORM using the AdonisJS CLI. This command adds the necessary package and configures it for your project. ```sh node ace add @adonisjs/lucid ``` -------------------------------- ### Register Preload File (Simple) Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/concepts/adonisrc_file.md Register a file to be imported when the application boots. This example shows a simple registration without environment constraints. ```ts { preloads: [ () => import('./start/view.js') ] } ``` -------------------------------- ### Logger Configuration Example Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/digging_deeper/logger.md The logger configuration is stored in `config/logger.ts`. This example shows the default configuration with a single logger named 'app'. ```typescript // title: config/logger.ts import env from '#start/env' import { defineConfig } from '@adonisjs/core/logger' export default defineConfig({ default: 'app', loggers: { app: { enabled: true, name: env.get('APP_NAME'), level: env.get('LOG_LEVEL', 'info') }, } }) ``` -------------------------------- ### Install @adonisjs/shield Package Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/security/securing_ssr_applications.md Install the shield package using the ace command. Ensure the session package is configured first as it is a peer dependency. ```sh node ace add @adonisjs/shield ``` -------------------------------- ### Create Inertia Starter Kit with Vue and No SSR Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/installation.md Initialize an AdonisJS project with the Inertia starter kit, configuring it for Vue and disabling server-side rendering. ```sh npm init adonisjs@latest -- -K=inertia --adapter=vue --no-ssr ``` -------------------------------- ### Install Pino Roll for File Rotation Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/digging_deeper/logger.md Install the 'pino-roll' package to handle automatic log file rotation, as Pino itself does not include this functionality. ```shell npm i pino-roll ``` -------------------------------- ### Install @adonisjs/lock Package Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/digging_deeper/locks.md Install the package using the Ace command. This command also registers the service provider and creates configuration files. ```bash node ace add @adonisjs/lock ``` -------------------------------- ### Execute main script Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/concepts/async_local_storage.md Runs the main application file to demonstrate the functionality of AsyncLocalStorage. ```sh node main.js ``` -------------------------------- ### Create Provider Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/references/commands.md Generates a new service provider file. Providers are stored in the providers directory. Use the --environments flag to specify import environments. ```bash node ace make:provider app ``` ```bash node ace make:provider app -e=web -e=console ``` -------------------------------- ### Getting All Intermediate Proxy IP Addresses Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/basics/request.md Use `request.ips()` to get an array of all IP addresses from intermediate proxies, sorted from most to least trusted. ```typescript import router from '@adonisjs/core/services/router' router.get('/', async ({ request }) => { console.log(request.ips()) }) ``` -------------------------------- ### Install API Client Plugin Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/testing/http_tests.md Install the Japa API client plugin using npm. This package is required for making HTTP requests in your tests. ```sh npm i -D @japa/api-client ``` -------------------------------- ### Install Transmit Package Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/digging_deeper/transmit.md Install the Transmit package using the Ace CLI. This command also registers the service provider and creates a configuration file. ```sh node ace add @adonisjs/transmit ``` -------------------------------- ### Initialize npm project Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/concepts/async_local_storage.md Initializes a new Node.js project. Ensure the package.json is updated to use the 'module' system. ```sh npm init --yes ``` ```json { "type": "module" } ``` -------------------------------- ### Install Packages Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/concepts/scaffolding.md Install one or more npm packages using the project's detected package manager. Specify whether each package should be a dev dependency. ```typescript const codemods = await command.createCodemods() try { await codemods.installPackages([ { name: 'vinejs', isDevDependency: false }, { name: 'edge', isDevDependency: false } ]) } catch (error) { console.error('Unable to install packages') console.error(error) } ``` -------------------------------- ### Execute Custom REPL Method Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/digging_deeper/repl.md Start the Ace REPL and execute the custom 'loadModels' method to import models. Use '.ls' to view available context methods and properties. ```bash node ace repl # Type ".ls" to a view list of available context methods/properties > (js) await loadModels() ``` -------------------------------- ### Start AdonisJS Dev Server with HMR Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/basics/vite.md Run the Ace command to start the AdonisJS development server with Hot Module Replacement enabled for Vite. ```sh node ace serve --hmr ``` -------------------------------- ### Create New AdonisJS Application with npm Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/installation.md Use npm init to create a new AdonisJS project. This command downloads the create-adonisjs initializer package. ```sh npm init adonisjs@latest hello-world ``` -------------------------------- ### Getting Accepted Content Types Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/basics/request.md Use `request.types()` to get a list of content types accepted by the client, ordered by preference. This is based on the `Accept` header. ```typescript import router from '@adonisjs/core/services/router' router.get('/', async ({ request }) => { console.log(request.types()) }) ``` -------------------------------- ### Create AdonisJS Project with MySQL Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/installation.md Initialize a new AdonisJS project with the MySQL database dialect specified. ```sh npm init adonisjs@latest hello-world -- --db=mysql ``` -------------------------------- ### Install Redis Package Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/database/redis.md Install the @adonisjs/redis package using the ace add command. This command also registers the service provider and creates the configuration file. ```sh node ace add @adonisjs/redis ``` -------------------------------- ### Create New AdonisJS Project Source: https://context7.com/adonisjs/v6-docs/llms.txt Use `npm init adonisjs@latest` to create a new project. Specify starter kits like 'web', 'api', 'slim', or 'inertia' with optional database and authentication configurations. ```sh # Requires Node.js >= 20 node -v # v22.0.0 # Interactive creation npm init adonisjs@latest hello-world # API project with PostgreSQL and access token auth npm init adonisjs@latest hello-world -- --kit=api --db=postgres --auth-guard=access_tokens # Full-stack web app with MySQL npm init adonisjs@latest hello-world -- --kit=web --db=mysql # Inertia + React with SSR npm init adonisjs@latest hello-world -- --kit=inertia --adapter=react --ssr # Start development server (with Hot Module Replacement) node ace serve --hmr # Compile TypeScript to JavaScript for production node ace build ``` -------------------------------- ### Install Vite Package with npm Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/basics/vite.md Use the Ace command to install the @adonisjs/vite package and Vite itself. This command also configures the project by creating necessary files. ```sh node ace add @adonisjs/vite ``` -------------------------------- ### Initialize OpenTelemetry (otel.ts) Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/digging_deeper/open_telemetry.md Create an otel.ts file to initialize the OpenTelemetry SDK. This file must be imported before any other code loads to ensure proper patching of libraries. ```typescript // title: otel.ts import { init } from '@adonisjs/otel/init' await init(import.meta.dirname) ``` -------------------------------- ### Create AdonisJS Project with API Kit and Access Tokens Guard Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/installation.md Initialize a new AdonisJS project using the API starter kit and configuring the access tokens authentication guard. ```sh npm init adonisjs@latest hello-world -- --kit=api --auth-guard=access_tokens ``` -------------------------------- ### Start Server with PM2 Source: https://github.com/adonisjs/v6-docs/blob/main/content/docs/getting_started/deployment.md Command to start your AdonisJS application using PM2 with the defined ecosystem configuration. PM2 will manage the application lifecycle, including restarts. ```sh // title: Start server pm2 start ecosystem.config.js ```