Please enable JavaScript.
Coggle requires JavaScript to display documents.
Adonisjs (HTTP lifecycle (introduction, routing, request, response, views,…
Adonisjs
-
-
configuration and Env
configuration debt
-
-
For a new user working on the code base for the first time, it becomes a nightmare to find all the configuration, and they keep juggling within multiple files/directories.
-
getting started
In AdonisJs, we store all the configuration inside a separate directory called config. All of the configuration files are loaded at boot time, and values can be accessed using the Config provider.
-
The values are fetched by defining the fileName.key. Nested values can be fetched using dot-notation.
Environment variables
Quite often you want to have a different configuration based upon the environment your code is running in. For example: Using sandbox secrets for a 3rd party service in development.
Also from the security point of view, you should never share your production credentials with all of the developers working on a codebase.
Instead, these credentials are stored as environment variables on your production server and defined inside .env file when developing the app locally.
Env.get always returns a string. If you want to get a boolean value you’ll need to check it as follows.
Env.get('…') === 'true'
-
-
disabling .env file
If .env file is missing, AdonisJs throws an exception by default. However, you turn off the exception as follows.
ENV_SILENT=true node server.js
testing variables
If your application is started with NODE_ENV=testing, AdonisJs attempts to load .env.testing file from the root of your application.
This file overrides the values from .env file, so that you can have slightly different configuration when running tests.
-
folder structure
-
App directory
The app directory stores all of your application code such as Controllers, Models, Commands.
AdonisJs has the concept of autoloading the app directory. This means that instead of requiring files with the relative path, you can require files with a namespace.
normally without autoload : const UserService = require('../app/Services/User')
with autoload : const UserService = use('App/Services/User')
The autoloading namespace is defined inside the package.json file. You are free to define more/unique namespaces.
views folder
The application views are stored inside resources/views directory. Each view file ends with .edge and uses edge as the templating engine.
command :
adonis make:view welcome
nested :
adonis make:view users.list
static Assets
description
The public directory in your app is dedicated to store all of the frontend related assets like css, images or javascript files.
-
-
config
To keep your applications away from configuration debt, AdonisJs gives you a dedicated directory /config to store all of the application configuration.
It is recommended to keep configuration at one place and make use of Environment variables for managing secrets.
Tests
All of the application tests are stored inside in the test directory. The testing package is not included by default and hence you can install it as defined here.
-
-
-
-
installation
-
- instal cli tools untuk mempermudah membut projek adonis dengan paket manager : npm i -g adonisjs/cli
- kemudian buat project dengan perintah : adonis new project_name
- running server dengan perintah : adonis serve --dev
The serve command starts the HTTP server on port defined inside the .env file in the project root. If you open 127.0.0.1:3333 inside your browser, you will see the following welcome page.
-
-
-
what is ?
AdonisJs is a Node.js web framework with a breath of fresh air and drizzle of elegant syntax on top of it. We prefer developer joy and stability over anything else.
-
-