This is the backend service for the docreader guide platform.
This project is a RESTful backend API for the docreader guide platform. It is built using Node.js, Express and Prisma.
npm>= 9.xpostgresqlrunning locally or remotely
git clone https://github.com/asaber3030/nodejs-docreader-faculty
cd nodejs-docreader-faculty
npm install
Before running the service, you must first create the .env file and populate the necessary environment variables. Refer to this section for details.
You must also make sure that you have a postgresql deployment running.
Run the following command to migrate the Prisma schema to it (after populating DATABASE_URL environment variable):
npx prisma generate
npx prisma migrate dev
npm run start
Consider creating a service script (for whatever init system your server distro uses) for the daemon, for better integration and management.
Create a .env file in the root directory and configure the following:
# Used to enable or disable debugging output
NODE_ENV='production'||'development' # defaults to 'production'
# Connection variables
PORT=tcp_port
# TLS variables
TLS_ENABLED='True'||'False' # defaults to 'False'
TLS_KEY_PATH=path_to_tls_private_key_pem_file
TLS_CERT_PATH=path_to_tls_certificate_chain
# Database variables
DATABASE_URL=database_url
# JWT variables
JWT_SECRET=secret(private_key)_for_signing_JWTs
JWT_COOKIE_EXPIRES_IN_DAYS=n_days_until_jwt_expires
JWT_PRIVATE_KEY_PATH=path_to_JWT_public_key
JWT_PUBLIC_KEY_PATH=path_to_JWT_private_key
# Google API client variables. Obtain and configure them from your GCP dashboard.
GOOGLE_CLIENT_ID=google_client_id
GOOGLE_CLIENT_SECRET=google_client_secret
GOOGLE_REDIRECT_URI=google_redirect_uri_for_oauth2_callback
# Firbase variables (used for notification system)
NEXT_PUBLIC_FIREBASE_PROJECT_ID=firebase_project_id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=firebase_storage_bucket
FIREBASE_PRIVATE_KEY_PATH=firebase_private_key_path
FIREBASE_CLIENT_EMAIL=firebase_client_emailThe scripts directory has some useful migration and seeding scripts. Here's a description of each one:
migrateDBPrisma.js: Copies data from v1 database to v2 database using Prisma. It needs a.envfile thatOLD_COMPILED_SCHEMA_PATHandNEW_COMPILED_SCHEMA_PATHvariables.migrateDBPG.ts: Copies data from v1 database to v2 database without Prisma dependency. It relies solely onpg(official postgres driver for nodejs) package. It is slower than the Prisma-dependent one, so that should be preferred. It needs a.envfile with two environment variables:OLD_DATABASE_URLandNEW_DATABASE_URLvariables.seedPermissions.js: Seeds permissions for all action, scope and resource combinations.seedRoles.js: Seeds the two default roles (SuperAdminat id 0 andUserat id 1) with expected (hard-coded) ids and appropriate permissions.