Create a database

How to create a database to your application

Every application needs to store data in a database at some point. You'll learn how to get a production-grade database from Qovery in just a few seconds in this guide.

Tutorial

Qovery supports most popular SQL and NoSQL databases (You can see the complete list here). In this guide we will deploy a PostgreSQL database and connect it to our NodeJS app.

  1. Create a PostgreSQL database

  2. Connect your application

    Now, we need to connect our application to our database. The credentials (URI, Username, Password ...) are available through environment variables. They are injected by Qovery when your application runs.

    To connect our NodeJS application to our PostgreSQL database, we only have to:

    • Use the NodeJS PostgreSQL client (pg)
    • Use QOVERY_DATABASE_MY_DB_CONNECTION_URI into our code

    Add the pg dependency into package.json

    {
    /* ... */
    "dependencies": {
    /* ... */
    "pg": "^7.17.0"
    }
    }

    Connect our application to PostgreSQL (see documentation)

    const { Pool } = require('pg')
    const pool = new Pool({
    connectionString: process.env.QOVERY_DATABASE_MY_DB_CONNECTION_URI,
    })
    // your can use your connection pool now ...

    Nothing more, well done! You can now be able to use your database.

Next Steps

Congratulations, your application has access to your PostgreSQL database. Now we will see how to add your custom domain to your service.