JS20

Documentation

JS20 - Documentation

Setup Database

Connect the application to any databases you intend to use.

dotenv.config({ quiet: true });

const connectOptions: MysqlConnectOptions = {
    host: process.env.SQL_HOST || '',
    port: parseInt(process.env.SQL_PORT || '5432'),
    user: process.env.SQL_USER || '',
    password: process.env.SQL_PASSWORD || '',
    database: process.env.SQL_DATABASE || '',
};

// Use any databases we support, or make your own!
const database = new MySqlDatabase(connectOptions);

// Register database with the app
app.addDatabase(database);

Provides the following output:

✓ MySQL connected
Express server is running on port 3000 🚀

What's happening here?

  • We use MySql as database
  • You can run app.addDatabase() multiple times if you need many different dbs
JS20