The Tweetr app will use MySQL for storage. So, we need to install Node.js driver for MySQL:

npm install mysql --save

With that installed, let's set up the app to use MySQL. Taking a look at config/database.js, you see config settings for different databases including MySQL. Though you can easily enter the MySQL settings directly in the config file, that will mean you’ll have to change these settings every time you change the application environment (development, staging, production etc.) which is actually a bad practice. Instead, we’ll make use of environment variables and depending on the environment the application is running on, it will pull the settings for that environment. We can easily do that with AdonisJS. All we have to do is enter the appropriate config settings in the .env file.

Open .env and update the DB details as below:

Table of Contents

    // .env
    
    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_USER=root
    DB_PASSWORD=
    DB_DATABASE=tweetr

    Replace DB_USER, and DB_PASSWORD accordingly with your own database settings. Then create a MySQL database with the name tweetr.

    Chimezie Enyinnaya

    16 posts

    Software Developer [PHP Laravel JavaScript NodeJS AdonisJS VueJS] | movie lover | run http://openlaravel.com