Backend
Table of contents
Getting started
The backend of the Junqo-platform is a NestJs application.
Its main goal is to provide a GraphQL API that enables efficient and flexible database interactions.
Prerequisites
Before you begin, ensure you have the following software installed:
- Node.js (version 14.x or higher)
- npm (comes with Node.js)
- PostgreSQL
Installation
-
Clone the repository:
git clone https://github.com/Junqo-org/junqo-platform.git cd junqo-platform
-
Navigate to the backend directory:
cd junqo_back
-
Install the dependencies:
npm install
Configuration
To configure the backend, you can use environment variables, .env
files in the junqo_back
directory or configuration files. If an environment variable is not found, the default value will be used.
Here is the list of environment variables used by the backend:
GRAPHQL_SCHEMAS_PATH
: The path to the GraphQL schemas. Default value is./../schemas
.DATABASE_HOST
: The host of the database. Default value islocalhost
.DATABASE_PORT
: The port of the database. Default value is5432
.DATABASE_USER
: The user of the database. Default value isjunqo
.DATABASE_NAME
: The name of the database. Default value isjunqo
.DATABASE_PASSWORD
: The password of the database. Optional, if set, used in priority toDATABASE_PASSWORD_FILE
.DATABASE_PASSWORD_FILE
: The path to the file containing the password of the database user. Default value is./../db_password.conf
.JWT_SECRET
: The secret used to sign the JWT tokens. Required.CORS_ORIGINS
: The URL of the frontend used for CORS. If not set accept requests from every origin.NODE_ENV
: The environment of the backend. Eitherdevelopment
orproduction
.
-
Create a
.env
file in the backend directory and add the following environment variables:# Database Configuration # DATABASE_HOST=localhost # DATABASE_PORT=5432 # DATABASE_NAME=your_db_name # DATABASE_USER=your_db_user # DATABASE_PASSWORD=your_db_password DATABASE_PASSWORD_FILE=/run/secrets/db_password # Security Configuration JWT_SECRET=not_for_production # Use a strong, unique value in production # Minimum 32 characters, randomly generated # Example: openssl rand -base64 32 # CORS Configuration (authorized source url). Default accept requests from every origin. # CORS_ORIGINS="http://localhost:80"
-
Ensure PostgreSQL is running and the database is set up with the provided credentials.
Running the Application
-
To start the application in development mode:
npm run start:dev
-
To start the application in production mode:
npm run start:prod
Basic Usage
Once the application is running, you can access the API at http://localhost:3000/graphql
. For detailed API documentation, refer to the API documentation.
Technologies
- NestJs
- It is a progressive Node.js framework for building efficient, reliable, and scalable server-side applications.
- PostgreSQL
- It is a powerful, open-source object-relational database system.
- Sequelize
- It is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite, and Microsoft SQL Server.
- Apollo Server
- It is a community-maintained open-source GraphQL server that works with many Node.js HTTP server frameworks.