DailyDesk Backend
This is the backend project for DailyDesk.
Prerequisites
It is recommended to use Node.js v16 for this project.
To manage multiple Node.js versions, we recommend using a version manager:
- macOS/Linux: nvm
- Windows: nvm-windows
Database & Cache
-
Redis: It is recommended to run Redis using Docker with the
redis-stackimage, which includes RedisInsight.Is running, you can access RedisInsight at http://localhost:8001. Install Docker Desktop if you haven't already.docker run --name daily-desk-redis -p 6379:6379 -p 8001:8001 -d redis/redis-stack:latest -
PostgreSQL: You can install PostgreSQL locally using Postgres.app (macOS) or the Windows Installer. Alternatively, you can run it via Docker.
You can also connect to the shared development database if credentials are provided.
-
pgAdmin 4: Recommended for managing PostgreSQL databases. Download pgAdmin 4.
Database Connection via SSH Tunnel
If the development database is located in a private network, this project includes an automated script to establish the SSH tunnel when you start the server.
- Ensure you have your Bastion SSH key (PEM file) available locally.
- In your
.envfile, configure the following:SSH_REMOTE_DB_HOST=<Actual RDS Endpoint> BASTION_KEY_PATH=<Absolute Path to PEM file> # Optional overrides # BASTION_HOST=ec2-98-81-247-161.compute-1.amazonaws.com # BASTION_USER=ec2-user - Set
DB_HOST=localhostin your.env.
When you run npm run start:dev, the script will automatically open the tunnel. Manual SSH connection is no longer required.
Environment Setup
- Run the setup script to create your
.envfile and look up AWS resources:npm run setup:envNote: This script automatically fetches configurations (including database credentials) for the Remote AWS Development Environment.
If you intend to run the application with a Local Database (via
Option 2below), you must manually update the following variables in your.envfile after running the script: *DB_HOST=localhost*DB_PORT=5432(or your local port) *DB_USERNAME=postgres(or your local user) *DB_PASSWORD=...*DB_NAME=... - Open the newly created
.envfile. - Replace the
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYvalues with the credentials provided by your administrator. - Verify other variables (Host, Port, Database Credentials, etc.) are correct.
Installation
Install the project dependencies using the --legacy-peer-deps flag:
npm install --legacy-peer-deps
Running the Application
Running the Application
There are two main ways to run the application in development mode, depending on which database you want to connect to.
Option 1: Connect to Remote AWS Dev Database
This option automatically opens an SSH tunnel to the AWS development database via a Bastion host.
Command:
npm run start:dev:remote
What happens:
1. The script (scripts/start-dev-remote.ts) reads your configured BASTION_HOST and BASTION_KEY_PATH.
2. It opens a secure SSH tunnel forwarding your local port (default 5433 or as configured in DB_PORT) to the remote RDS instance.
3. It starts the NestJS server (nest start --watch).
Note: The Bastion host is an EC2 instance. If this instance is rebooted, its public IP address may change. If you cannot connect, verifying the current BASTION_HOST IP address.
Option 2: Connect to Local Database
Use this option if you are running a local PostgreSQL instance and do not need the remote data.
Command:
npm run start:dev
What happens:
1. The application starts immediately (nest start --watch).
2. It attempts to connect to the database configured in your .env (typically localhost on DB_PORT) without establishing a tunnel.
3. Ensure your local PostgreSQL service is running and matches the credentials in .env.
TypeORM Migrations
List all available migration commands:
npm run typeorm:cli
Generate initial migration from TypeORM Entities:
npm run migration:generate -- -n <MIGRATION_NAME>
Create a migration file:
npm run migration:create -- -n <MIGRATION_NAME>
Run all new migrations:
npm run migration:run
License
Nest is MIT licensed.