Setting up environment
RecNet-Api

RecNet-Api

Recnet-api is a backend API service for Recnet (opens in a new tab). Powered by Node.js and NestJS (opens in a new tab), it offers scalable solutions for paper recommendation, news feed system and academic social media network.

Requirements

  • node >= 18
  • PostgreSQL 16

Documentation

Local Development

Installation

pnpm install

Prepare environment variable

  1. Copy from sample file
cp apps/recnet-api/.env.sample apps/recnet-api/.env
  1. Modify environment variable
  2. Source the .env file
source apps/recnet-api/.env

Set up a local DB

  1. Use docker to create a PostgreSQL container.
# create and start
docker create --name recnet-postgres -p 5432:5432 -e POSTGRES_PASSWORD=admin postgres:16.2
docker start recnet-postgres
 
# stop and remove
docker stop recnet-postgres
docker rm recnet-postgres
  1. Dump the remote database to local
# if you don't have Postgres CLI, install libpq, postgresql first
brew install libpq  # macOS
brew install postgresql@16  # macOS
 
# copy from sample file and modify the .env.dbdump.local
cp apps/recnet-api/scripts/.env.dbdump.sample apps/recnet-api/scripts/.env.dbdump.local
 
# dump the remote database to local
nx db:dump recnet-api
  1. Run Prisma Studio to see database at localhost:5555.
nx prisma:studio recnet-api

Run the server

nx serve recnet-api

DB Migration

How to generate migration files?

  1. Prepare a local database. Same as here.
  2. Modify apps/recnet-api/prisma/prisma.schema
  3. Run migration script. The migration script will create a directory under apps/recnet-api/prisma/migrations with migration.sql and down.sql.
nx prisma:migrate recnet-api {migration_name}

How does the migration script been deployed to dev or production environment?

If the environment variable DB_MIGRATE=true, the migration will be deployed when the server is up. It is executed by prisma.connection.provider.ts.

Environment and Deployment

We currently maintain two environment - dev and prod. All of the services are deployed to AWS Elastic Beanstalk.

API host

Deployment

We utilize AWS CodePipeline to build up the CI/CD for the services. Whenever the designated branch updates, the pipeline will deploy the code on that branch to the corresponding environment.

  • dev branch: recnet-api-dev
  • prod branch: master