How can i deploy Adonis-js 5 on Digital Ocean

454 Views Asked by At

I am trying to deploy Adonisjs 5 API using on Digital Ocean. I encountered an error relating to .env. Below is the code bbase of the error.

gmh@ubuntu-gmh:~/www/gmh-api$ cd build
gmh@ubuntu-gmh:~/www/gmh-api/build$ node ace migration:run --force

  Exception 

 E_MISSING_ENV_VALUE: Missing environment variable "DB_CONNECTION"


gmh@ubuntu-gmh:~/www/gmh-api/build$ 

I have DB_CONNECTION declared in .env file

PORT=3333
HOST=127.0.0.1
NODE_ENV=production
DRIVE_DISK=local

DB_CONNECTION=mysql

Below is the database configuration code:

  connection: Env.get('DB_CONNECTION'),

  connections: {
    /*
    |--------------------------------------------------------------------------
    | MySQL config
    |--------------------------------------------------------------------------
    |
    | Configuration for MySQL database. Make sure to install the driver
    | from npm when using this connection
    |
    | npm i mysql2
    |
    */
    mysql: {
      client: 'mysql2',
      connection: {
        host: Env.get('MYSQL_HOST'),
        port: Env.get('MYSQL_PORT'),
        user: Env.get('MYSQL_USER'),
        password: Env.get('MYSQL_PASSWORD', ''),
        database: Env.get('MYSQL_DB_NAME'),
      },

n/b: mysql is installed on the nginx server on Digital Ocean

Pls guys, an helpfull insight is welcome.

I tried running:

node ace migration:run --force  

inside the build folder root, afterwhich i got:

 Exception 

 E_MISSING_ENV_VALUE: Missing environment variable "DB_CONNECTION"
1

There are 1 best solutions below

0
On

Move to the root directory of your project and run your migration command:

node ace migration:run --force  

If you encounter this error:

create table `adonis_schema_versions` (`version` int not null) - Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set.

Visit this answer in this link.