NileJS SDK can be configured using both environment variables and a configuration object. If both are provided, the configuration object will take precedence. This document describes the available configuration options, and how to set them using either method.

SDK Configuration

The following configuration options are available at the overall SDK level:
Configuration OptionEnvironment VariableRequiredDefaultDescription
databaseIdNILEDB_ID or NILEDB_API_URLYes-The ID of the database to use
userNILEDB_USERYes-The user to use for the database
passwordNILEDB_PASSWORDYes-The password to use for the database
databaseNameNILEDB_NAME or NILEDB_POSTGRES_URLYes-The name of the database to use
tenantIdNILEDB_TENANTNo-Current tenant ID used for scoping API and DB calls
userId-No-Optional user identifier used for DB access, e.g. for impersonation
debug-NofalseWhether to enable debug logging
apiUrlNILEDB_API_URLNo-Base URL for Nile Auth requests
callbackUrlNILEDB_CALLBACK_URLNo-Used to override the client-provided callback URL during authentication
origin-No-Controls origin used in requests (e.g. for cookie handling in cross-origin apps)
headers-No-Additional headers sent with API requests. Include cookie for session management
routes-No-Overrides for default auth routes (e.g. signin path)
routePrefix-No/apiPrefix for API routes
secureCookiesNILEDB_SECURECOOKIESNoBased on NODE_ENVEnforces use of secure cookies
extensions-No-Array of pre/post-processing hooks for each API request
preserveHeaders-NofalseWhether to retain incoming headers across extension execution
logger-No-Optional custom logger implementation
db-No-Database connection pool configuration (see below)

Database Configuration

The db object configures the connection to Postgres, using settings compatible with the pg library.
Configuration OptionEnvironment VariableRequiredDefaultDescription
userNILEDB_USERNo-Will default to the top-level user config if not set
passwordNILEDB_PASSWORDNo-Will default to the top-level password if not set
hostNILEDB_HOST or NILEDB_POSTGRES_URLNodb.thenile.devPostgres host
portNILEDB_PORT or NILEDB_POSTGRES_URLNo5432Postgres port
databaseNILEDB_NAME or NILEDB_POSTGRES_URLNo-Postgres database name
connectionString-No-Full connection string. Overrides other DB config values
ssl-No-TLS socket options for secure DB connection
types-No-Custom Postgres type parsers
statement_timeout-No-Statement timeout in ms
query_timeout-No-Query timeout in ms
lock_timeout-No-Lock timeout in ms
application_name-No-Name used by the DB client connection
connectionTimeoutMillis-No-How long to wait before failing a DB connection attempt
idle_in_transaction_session_timeout-No-Idle timeout for sessions with open transactions
idleTimeoutMillis-No10000Time a client can sit idle before being dropped
max-No10Max number of DB clients in the pool
allowExitOnIdle-NofalseAllow Node to exit early when pool is idle

Example Configurations

Basic configuration with environment variables

NILEDB_USER=0195f45d-c3ca-7b29-8a9c-717a99d993a1
NILEDB_PASSWORD=5e64c8e9-8ac7-4c0d-b6f1-dab7672fe1be
NILEDB_API_URL=https://us-west-2.api.thenile.dev/v2/databases/0195f4dd-22d3-68c6-a6c1-1ddc24f0f37c
NILEDB_POSTGRES_URL=postgres://us-west-2.db.thenile.dev:5432/my_database

Basic configuration with configuration object

nile.ts
import { Nile } from '@niledatabase/server';

const nile = Nile({
  databaseId: '0195f4dd-22d3-68c6-a6c1-1ddc24f0f37c',
  databaseName: 'my_database',
  user: '0195f45d-c3ca-7b29-8a9c-717a99d993a1',
  password: '5e64c8e9-8ac7-4c0d-b6f1-dab7672fe1be',
  apiUrl: 'https://us-west-2.api.thenile.dev/v2/databases/0195f4dd-22d3-68c6-a6c1-1ddc24f0f37c',
  db: {
    host: 'us-west-2.db.thenile.dev',
  }
});

Production configuration

NILEDB_USER=0195f45d-c3ca-7b29-8a9c-717a99d993a1
NILEDB_PASSWORD=5e64c8e9-8ac7-4c0d-b6f1-dab7672fe1be
NILEDB_API_URL=https://us-west-2.api.thenile.dev/v2/databases/0195f4dd-22d3-68c6-a6c1-1ddc24f0f37c
NILEDB_POSTGRES_URL=postgres://us-west-2.db.thenile.dev:5432/my_database
DEBUG=false

Cross-origin configuration

NILEDB_USER=0195f45d-c3ca-7b29-8a9c-717a99d993a1
NILEDB_PASSWORD=5e64c8e9-8ac7-4c0d-b6f1-dab7672fe1be
NILEDB_API_URL=https://us-west-2.api.thenile.dev/v2/databases/0195f4dd-22d3-68c6-a6c1-1ddc24f0f37c
NILEDB_POSTGRES_URL=postgres://us-west-2.db.thenile.dev:5432/my_database