Getting Started

  1. Initial Set Up
  2. Configuration
  3. Running the Applications

Initial Set Up

Once the repository has been created, you'll need to install the project's dependencies:

$ yarn

Environment files will also be needed for later configuration. Please rename the example files so that configuration data will be recognized at run time:

$ mv .env.example .env

# this is only needed if you plan on using Nx Cloud
$ mv nx-cloud.env.example nx-cloud.env

Database

This backend requires a database connection for data storage. During development I defaulted to a PostgreSQL database running via Docker, but SQLite can be used as well.

Docker Instructions

$ docker-compose up -d

The docker-compose.yml file includes the Alpine-based postgres image as well as Adminer with a Web UI for graphically managing your database. The Adminer UI will be available at [http://localhost:8080].

By default a local directory will be used for data persistence ({projectRoot}/tmp/pgdata). This can be changed or removed in the docker-compose.yml file.

SQLite Instructions

No special configuration is required - see Configuration for connection details. If a .sqlite file is not available when the application first runs, it will be created.

Configuration

All configuration (except for Nx Cloud) is handled in the .env file we created earlier. Here is an explanation of the settings currently exposed in that file:

VariablePurposeNotes
NODE_ENV
ENVIRONMENTUsed to determine where the application is running (CI pipeline, local, prod, etc)
API_VERSIONREST API uses versioned routes for easy evolution over time. Setting this will change the version exposed by the API.
API_PREFIXDefaults to /api, this allows customization of the API endpoints paths (ex: /api/v1/my-endpoint)
CORS_ORIGINSTells NestJS which origins to trust, defaults to *
ENABLE_SWAGGERToggles whether Swagger docs UI will be exposed
GENERATE_SWAGGER_JSONGenerates a swagger.json file if true
JWT_ACCESS_EXPIRATION_TIMETime before an access token expires (ex: 3600s or 2d)
JWT_ACCESS_EXPIRATION_TIMETime before a refresh token expoires (ex: 7d or 1w)
JWT_ACCESS_SECRETStrong secret used to sign JWTsMUST be different from the refresh token secret. Can be generated using this following shell command:
node -e "console.log(require('crypto').randomBytes(256).toString('base64'));"
JWT_REFRESH_SECRETSee JWT_ACCESS_SECRET
SERVER_HOSTREST API host (ex: localhost, my-app.com)
SERVER_PORTPort where REST API is exposed
SWAGGER_JSON_FILEName of the file to be generated, if enabled
DATABASE_TYPEDefaults to sqlite, but postgres can be used as well.PostgreSQL and SQLite are the only databases that have been tested. More infomation on configuring TypeORM can be found in their source code: DataSourceOptions.tsopen in new window
DATABASE_HOSTHost where database is runningNot required for SQLite
DATABASE_PORTPort where database is runningNot required for SQLite
DATABASE_USERNAMEDatabase user for connectionNot required for SQLite
DATABASE_PASSWORDDatabase password for connectionNot required for SQLite
DATABASE_NAMEName of database to create
DATABASE_PATHPath to SQLite fileRequired for SQLite only
DATABASE_LOGGING_ENABLEDToggle additional, database-specific logging
DATABASE_SYNCHRONIZEAutomatically sync tables/entities with the applicationNot supposed to be used for production!
SENTRY_DSNOptional DSN URL for Sentry error reporting
SOCIAL_GOOGLE_ENABLEDBoolean that toggles Google OAuth integration
SOCIAL_GOOGLE_CLIENT_ID
SOCIAL_GOOGLE_CLIENT_SECRET
EMAIL_ENABLEDOptional boolean that toggles SMTP transport abilities
EMAIL_HOSTSMTP Host
EMAIL_PORTSMTP port
EMAIL_USER
EMAIL_PASSWORD
EMAIL_TEMPLATE_DIRPath relative to project root of Handlebars files used for emails
EMAIL_PARTIALS_DIRPath relative to project root of Handlebars partials that can be included in templates
EMAIL_IGNORE_TLS
EMAIL_REQUIRE_TLS
EMAIL_DEBUG
EMAIL_DEFAULT_NAMEDefault sender name for emails
EMAIL_DEFAULT_EMAILDefault sender email for outgoing email
EMAIL_SECURE

Running

With your database and configuration in place, you should be able to run one of the following commands:

# to run just the REST API
$ nx serve server

# to run both the client and API simutaneously
$ nx run-many --target=serve --all