# Database Setup

ExpressWebJs makes interacting with SQL and NOSQL databases extremely easy across a variety of supported database.

  • MySql
  • MariaDB
  • PostgreSQL
  • Amazon Redshift
  • SQLite3
  • Oracle
  • MicroSoft SQL
  • MongoDB

Befor we continue, if you've not created your .env file, quickly do that by copying example.env to .env file or you can run the following command in your terminal:

   cp example.env .env
Copied!

Now that our .env file is ready, the configuration for ExpressWebJs database is located in 📘 Config/database.ts file. In this file, you may define all of your database connections, as well as specify which connection should be used by default. Most of the configuration options within this file are driven by the values of your application's environment variables.

# SQL Database configuration

You can easily configure your environment variables to point to your database by placing the connection values in the .env file. Let's connect to mysql database by updating these values:

DB_SHOULD_CONNECT = true;
DB_DRIVER = postgres;
DB_HOST = localhost;
DB_PORT = 5444;
DB_USER = postgres;
DB_PASSWORD = database_password;
Copied!

# NOSQL Database configuration

You can configure your nosql database environment variables to point to your database by placing the connection values in the .env file. Let's connect to mongoDB by updating these values.

DB_SHOULD_CONNECT = true;
DB_CONNECTION = mongoose;
DB_HOST = localhost;
DB_PORT = 27017;
DB_USER = database_user;
DB_PASSWORD = database_password;
DB_DATABASE = database;
DB_USENEWURLPARSER = true;
DB_USEUNIFIEDTOPOLOGY = true;
DB_USECREATEINDEX = true;
Copied!

Once that is done, you need to select the ORM to work with. Read Supported ORMs in ExpressWebJs