This document provides instructions on how to set up and start a running instance of talawa-api on your local system. The instructions are written to be followed in sequence so make sure to go through each of them step by step without skipping any sections.
- Talawa-API Installation
- Table of Contents
- Installation Steps Summary
- Prerequisites
- Installation Using Docker
- Installation without Docker
- Configuration
- Automated Configuration of
.env
- Manual Configuration of
.env
- The Environment Variables in
.env
- Changing the Development Environment in the .env file
- Generating Token Secrets
- Setting up REFRESH_TOKEN_SECRET in the .env file
- Configuring MongoDB in the .env file
- Configuring Redis in .env file
- Setting up .env LAST_RESORT_SUPERADMIN_EMAIL parameter in the .env file
- Configuring Google ReCAPTCHA in the .env file
- Setting up SMTP Email Variables in the .env File
- Setting up MinIO configurations
- Setting up Logger configurations
- The Environment Variables in
- Automated Configuration of
- Importing Sample Database
- Running Talawa-API
- How to Access the Talawa-API URL
- Accessing MongoDB
- Manually Adding The First Super Admin User
- Other
- Testing
- Installation Steps Summary
- Prerequisites
- Installation Using Docker
- Installation without Docker
- Configuration
- Automated Configuration of
.env
- Manual Configuration of
.env
- The Environment Variables in
.env
- Changing the Development Environment in the .env file
- Generating Token Secrets
- Setting up REFRESH_TOKEN_SECRET in the .env file
- Configuring MongoDB in the .env file
- Configuring Redis in .env file
- Setting up .env LAST_RESORT_SUPERADMIN_EMAIL parameter in the .env file
- Configuring Google ReCAPTCHA in the .env file
- Setting up SMTP Email Variables in the .env File
- Setting up MinIO configurations
- Setting up Logger configurations
- The Environment Variables in
- Automated Configuration of
- Importing Sample Database
- Running Talawa-API
- How to Access the Talawa-API URL
- Accessing MongoDB
- Manually Adding The First Super Admin User
- Other
- Testing
Installation is not difficult, but there are many steps. This is a brief explanation of what needs to be done:
- Install
git
- Download the code from GitHub using
git
- Install
node.js
(Node), the runtime environment the application will need to work. - Configure the Node Package Manager (
npm
) to automatically use the correct version of Node for our application. - Use
npm
to install TypeScript, the language the application is written in. - Install other supporting software such as the database using either:
- Docker
- A manual setup
- Configure the application
- Start the application
These steps are explained in more detail in the sections that follow.
In this section we'll explain how to set up all the prerequisite software packages to get you up and running.
The easiest way to get the latest copies of our code is to install the git
package on your computer.
Follow the setup guide for git
on official git docs. Basic git
knowledge is required for open source contribution so make sure you're comfortable with it. Here's a good tutorial to get started with git
and github
.
First you need a local copy of talawa-api
. Run the following command in the directory of choice on your local system.
-
On your computer, navigate to the folder where you want to setup the repository.
-
Open a
cmd
(Windows) orterminal
(Linux or MacOS) session in this folder.- An easy way to do this is to right-click and choose appropriate option based on your OS.
-
For Our Open Source Contributor Software Developers:
-
Next, we'll fork and clone the
talawa-api
repository. -
In your web browser, navigate to https://github.com/PalisadoesFoundation/talawa-api/ and click on the
fork
button. It is placed on the right corner opposite the repository namePalisadoesFoundation/talawa-api
. -
You should now see
talawa-api
under your repositories. It will be marked as forked fromPalisadoesFoundation/talawa-api
-
Clone the repository to your local computer (replacing the values in
{{}}
):$ git clone https://github.com/{{YOUR GITHUB USERNAME}}/talawa-api.git cd talawa-api git checkout develop
- Note: Make sure to check out the
develop
branch
- Note: Make sure to check out the
-
You now have a local copy of the code files. For more detailed instructions on contributing code, and managing the versions of this repository with
git
, checkout our CONTRIBUTING.md file.
-
-
Talawa Administrators:
-
Clone the repository to your local computer using this command:
$ git clone https://github.com/PalisadoesFoundation/talawa-api.git
-
Best way to install and manage node.js
is making use of node version managers. We recommend using fnm
, which will be described in more detail later.
Follow these steps to install the node.js
packages in Windows, Linux and MacOS.
- For Windows:
- first install
node.js
from their website at https://nodejs.org- When installing, don't click the option to install the
necessary tools
. These are not needed in our case.
- When installing, don't click the option to install the
- then install fnm. Please read all the steps in this section first.
- All the commands listed on this page will need to be run in a Windows terminal session in the
talawa-api
directory. - Install
fnm
using thewinget
option listed on the page. - Setup
fnm
to automatically set the version ofnode.js
to the version required for the repository using these steps:- First, refer to the
fnm
web page's section onShell Setup
recommendations. - Open a
Windows PowerShell
terminal window - Run the recommended
Windows PowerShell
command to opennotepad
. - Paste the recommended string into
notepad
- Save the document.
- Exit
notepad
- Exit PowerShell
- This will ensure that you are always using the correct version of
node.js
- First, refer to the
- All the commands listed on this page will need to be run in a Windows terminal session in the
- first install
- For Linux and MacOS, use the terminal window.
- install
node.js
- then install
fnm
- Refer to the installation page's section on the
Shell Setup
recommendations. - Run the respective recommended commands to setup your node environment
- This will ensure that you are always using the correct version of
node.js
- Refer to the installation page's section on the
- install
TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. It adds optional types, classes, and modules to JavaScript, and supports tools for large-scale JavaScript applications.
To install TypeScript, you can use the npm
command which comes with node.js
:
npm install -g typescript
This command installs TypeScript globally on your system so that it can be accessed from any project.
Run the following command to install the packages and dependencies required by the app:
npm install
The prerequisites are now installed. The next step will be to get the app up and running.
This guide provides step-by-step instructions on deploying a talawa-api using Docker. Docker allows you to package your application and its dependencies into a container, providing a consistent environment across different systems.
Here is a list of steps to follow:
- Run the application setup procedure
- Install the Docker application
- Install the Docker helper
- Install other supporting software such as the database using the
docker-compose
command. - Start Docker using the
docker-compose
command - Import the sample data into the database
We have created a setup script to make configuring Talawa-API easier.
- You can do this by running the command below.
- Default answers will be given with capital letters
- Details of what each prompt means can be found in the Configuration section of this document.
npm run setup
There are many ways to install Docker. We reccommend using Docker Desktop. It can be downloaded here:
- Download Docker Desktop using this link.
- Docker Desktop installed on your machine.
After installing Docker, you'll need to tell Docker to install the additional software it will need to run the application.
The setup steps differ depending on whether you are working in a development or production environment.
Follow these steps for setting up a software development environment.
-
Building and Starting Development Containers:
-
Using Windows:
docker-compose -f docker-compose.dev.yaml up --build
-
Using Ubuntu: 1. Running synchronously. Using CTRL-C will stop it.
bash sudo /usr/libexec/docker/cli-plugins/docker-compose -f docker-compose.dev.yaml up --build
2. Running asynchronously in a subshell. You will have to use thedocker-compose down
command below to stop it.bash sudo /usr/libexec/docker/cli-plugins/docker-compose -f docker-compose.dev.yaml up --build &
This command starts the development environment, where you can make changes to the code, and the server will automatically restart.
-
-
Accessing the Development Application: Open your web browser and navigate to:
http://localhost:4000
-
Stopping Development Containers:
-
Using Windows:
docker-compose -f docker-compose.dev.yaml down
-
Using Ubuntu:
sudo /usr/libexec/docker/cli-plugins/docker-compose -f docker-compose.dev.yaml down
-
Follow these steps for setting up a production environment.
-
Building and Starting Production Containers:
docker-compose -f docker-compose.prod.yaml up --build -d
This command starts the production environment in detached mode, suitable for production deployment.
-
Accessing the Production Application:Open your web browser and navigate to:
http://localhost:4001
-
Stopping Production Containers:
docker-compose -f docker-compose.prod.yaml down
Note: If you're using Docker, you'll need to manually import the sample data after the Docker Compose has started the MongoDB container. For instructions on how to do this, refer to Importing Sample Database
You'll need to manually import the sample data after the Docker Compose has started the MongoDB container. For instructions on how to do this, refer to the Importing Sample Database section of this document.
There are more steps, but the outcome is the same. A working Talawa-API instance.
Install the packages required by talawa-api
using this command:
npm install
Talawa-api makes use of MongoDB
for its database needs. We make use of mongoose ODM
to interact with the MongoDB database from within the code.
We're listing some common approaches to set up a running instance of MongoDB database:
System native database approach:
(Highly Recommended) You can install MongoDB natively on your system and create/connect to the database. Follow the setup guide on official MongoDB Docs for your respective operating system.Hosted database approach:
MongoDB Atlas is the easiest way to get a running instance of mongodb database. It is a hosted(remote) mongodb database provided by mongodb itself. If you're a beginner and don't want too much of a hassle setting up the database you should use this approach but you should eventually switch to local instance. Follow the setup guide on official MongoDB Atlas Docs. Mongodb Atlas is just one of the many hosted database solutions. Some issues that you might face while using this are slower tests, slower API requests, dependence on Internet connection etc.Docker container approach:
If you are fluent in working with docker you should use this approach. Docker is a great way to manage and run applications without natively installing anything on your system. With this you can set up the mongodb database inside a docker container and manage it as per your will. Follow this video tutorial to set up a mongodb docker container. You can learn about docker from Docker docs.
Talawa-api makes use of Redis
for caching frequently accessed data items in the primary database. We make use of ioredis
to interact with the redis-server
from within the code. The main Idea is the in production this will act as an in-memory cache. So it is recommended that you set it up locally. However for simplicity purposes, a section to accommodate for setting Redis up using a remote instance like Redis Cloud has been added. Please note that this is not recommended since the remote connection takes a considerable amount of time to be considered as a cache to improve application performance.
-
For Linux Users
: If you are using a Linux distribution, follow these steps to set up Redis:-
Open a terminal.
-
Update the package list:
sudo apt update
-
Install Redis Server:
sudo apt install redis-server
-
Start the Redis service:
sudo service redis-server start
-
Test if Redis is running by running the Redis CLI:
redis-cli
-
Use these parameters when running the setup script if you have configured the server on your local machine:
- Redis Host:
localhost
- Redis Port:
6379
(default Redis port)
- Redis Host:
-
-
For Windows Users using WSL
: If you'd rather not deal with the hassle of setting up WSL on your computer, there's another option: you can use a hosted database like Redis Cloud. More details about this are provided below, mainly for when you're working on development tasks. But it's a good idea to set up Redis on your own computer if you can. Right now, Redis isn't supported directly on Windows – you can only install and use it through WSL. If you're a Windows user and want to get Redis working using the Windows Subsystem for Linux (WSL), just follow these steps:-
Install WSL (Windows Subsystem for Linux) following the official WSL Installation Guide.
-
Open a WSL terminal.
-
Update the package list:
sudo apt update
-
Install Redis Server:
sudo apt install redis-server
-
Start the Redis service:
sudo service redis-server start
-
Test if Redis is running by running the Redis CLI:
redis-cli
-
Use these parameters when running the setup script if you have configured the server on your local machine:
- Redis Host:
localhost
- Redis Port:
6379
(default Redis port)
- Redis Host:
-
-
Connecting to Redis Cloud:
To connect to a Redis cloud service, you will need the host and port information provided by your cloud service provider. Use these values in your application to establish a connection. Typically, the host and port strings are provided in the following format:
- Host:
your-redis-host.redisprovider.com
- Port:
6379
(default Redis port)
Replace
your-redis-host.redisprovider.com
with the actual host provided by your Redis cloud service. You can then use these values in your application's configuration to connect to your Redis cloud instance. You may also have to enter Redis Password and Username for using cloud instance. - Host:
Remember to adjust any paths or details as needed for your specific environment. After following these steps, you will have successfully set up Redis.
Talawa-API uses MinIO, an open-source object storage system, for storing uploaded files. MinIO will be hosted alongside Talawa-API itself, providing a self-contained solution for file storage.
You can either use the setup script for automatic configuration or install MinIO manually.
-
Run the setup script.
-
The script will automatically set up environment variables, including MinIO credentials.
Details of what each prompt means can be found in the Configuration section of this document.
npm run setup
If you choose to set up MinIO manually, follow the instructions for your operating system below. Note that the MinIO server should not be started manually as it will be handled by the Talawa-API.
-
For Linux Users
- Download and Install MinIO
wget https://dl.min.io/server/minio/release/linux-amd64/archive/minio_20240817012454.0.0_amd64.deb -O minio.deb sudo dpkg -i minio.deb
- Follow the official installation guide: MinIO Installation Guide for Linux
- Download and Install MinIO
-
For Windows Users
- Download and Install MinIO
https://dl.min.io/server/minio/release/windows-amd64/minio.exe
- Follow the official installation guide: MinIO Installation Guide for Windows
- Download and Install MinIO
-
For macOS Users
- Download and Install MinIO
brew install minio/stable/minio
- Follow the official installation guide: MinIO Installation Guide for macOS
- Download and Install MinIO
You can run MinIO alongside Talawa-API using Docker or locally. Both methods ensure that MinIO is set up and running with Talawa-API.
To run MinIO along with Talawa-API using Docker, use the following command:
docker compose -f <docker-compose-file-name> up
Replace <docker-compose-file-name>
with the name of the Docker Compose file. This command will start both the Talawa-API and MinIO services as defined in the Docker Compose file.
If you prefer to run MinIO and Talawa-API locally, use the provided npm scripts. These scripts will ensure that MinIO is installed (if not already) and start the Talawa-API server along with MinIO.
-
To run the development server with MinIO:
npm run dev:with-minio
-
To start the production server with MinIO:
npm run start:with-minio
These npm scripts will check if MinIO is installed on your system. If MinIO is not installed, the scripts will install it automatically before starting the Talawa-API server.
You can customize the local storage path for MinIO in one of the following ways:
-
Using the Setup Script: During the configuration process, the setup script allows you to specify a custom path for MinIO's local data directory. Follow the prompts to set
MINIO_DATA_DIR
to your desired path. -
Manually Editing the .env File: Directly modify the
MINIO_DATA_DIR
environment variable in the.env
file to point to a different directory for storing MinIO's data.
-
MinIO Server:
- If using Docker, the server will be accessible at
http://minio:9000
. - If not using Docker, the server will be accessible at
http://localhost:9000
.
- If using Docker, the server will be accessible at
-
MinIO Console (Web UI): Access the console at
http://localhost:9001
.
After logging into the MinIO web UI, create a bucket with the name specified in your .env
file under the MINIO_BUCKET
variable.
It's important to configure Talawa-API to complete it's setup.
A configuration file named .env
is required in the root directory of Talawa-API
for storing environment variables used at runtime. It is not a part of the repo and you will have to create it.
You can use our interactive setup script to populate the .env
file using the command below.
This will create a new .env
file for you, and if one already exists, it will make the updates you require.
npm run setup
It can be done manually as well and here's how to do it.
NOTE: Use the steps below if you decided not to use the automated configuration approach.
With a fresh installation, you will not see a .env
file present. To manually create one, you will need to copy the contents of the .env.sample
file provided to .env
.
Use this command to do this
cp .env.sample .env
This .env
file must be populated with the following environment variables for talawa-api to work:
Variable | Description |
---|---|
NODE_ENV | Used for providing the environment in which the the talawa-api is running |
SERVER_PORT | Used for specifying the port on which the talawa-api is running |
ACCESS_TOKEN_SECRET | Used for signing/verifying JWT tokens |
REFRESH_TOKEN_SECRET | Used for signing/verifying JWT tokens |
MONGO_DB_URL | Used for connecting talawa-api to the mongoDB database |
RECAPTCHA_SECRET_KEY | Used for authentication using reCAPTCHA |
RECAPTCHA_SITE_KEY | Used for authentication using reCAPTCHA |
MAIL_USERNAME | Used for mailing service |
MAIL_PASSWORD | Used for mailing service |
LAST_RESORT_SUPERADMIN_EMAIL | Used for promoting the default super admin |
COLORIZE_LOGS | Used for colorized log formats in console |
LOG_LEVEL | Used for setting the logging level |
REDIS HOST | Used for connecting talawa-api to the redis instance |
REDIS_PORT | Specifies the port of the active redis-server |
REDIS_PASSWORD(optional) | Used for authenticating the connection request to |
a hosted redis-server | |
MINIO_ENDPOINT | Used for connecting talawa-api to the MinIO storage. |
MINIO_ROOT_USER | Used to authenticate with the MinIO server. |
MINIO_ROOT_PASSWORD | Used to authenticate with the MinIO server. |
MINIO_BUCKET | Used for the bucket name in the MinIO storage. |
MINIO_DATA_DIR | Defines the local directory path for MinIO storage. |
The following sections will show you how to configure each of these parameters.
Change the NODE_ENV
environment variable in the .env
file from production
to development
:
NODE_ENV=development
Access and refresh token secrets are used for authentication purposes.
Run the following command and copy/paste the result to the variable named ACCESS_TOKEN_SECRET
in .env
file.
The command to use is:
openssl rand -hex 32
This command is available if you have Git for Windows installed. Follow these steps:
-
Install
Git for Windows
-
Run the Git Bash app
-
Issue the this command:
openssl rand -hex 32
Run the following command and copy/paste the result to the variable named REFRESH_TOKEN_SECRET
in .env
file.
openssl rand -hex 32
Here's how you will configure MongoDB.
NOTE: Talawa-API uses 2 databases, a primary and test version.
- You only have to setup one database and provide it's URL in the
.env
file. This is theprimary database
and is used to store all your data. - We automatically create a new database with the name
TALAWA_API_TEST_DATABASE
. This is exclusively used for storing all the test data generated during the testing process so that it does not bloat the main database with unnecessary data.
A Connection String
is the URL that applications use to access a MongoDB database. Talawa-API will need to know the correct connection string to use to perform correctly.
- The
Connection String
is the.env
variable namedMONGO_DB_URL
in the.env
file. - The
Connection String
can differ depending on the approach you used to set up your database instance. Please read the official mongodb docs onconnection string
.
Your MongoDB installation may include either the mongo
or mongosh
command line utility. An easy way of determining the connection string
is to:
-
Run the command line utility
-
Note the
connection string
in the first lines of the output. -
Add the first section of the
connection string
to theMONGO_DB_URL
section of the.env
file. In this case it ismongodb://127.0.0.1:27017/
$ mongosh Current Mongosh Log ID: e6ab4232a963d456920b3736 Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.6.2 Using MongoDB: 6.0.4 Using Mongosh: 1.6.2 For mongosh info see: https://docs.mongodb.com/mongodb-shell/ ... ... ... ...
There are a few more steps that need to be done in a Windows environment.
-
Download the MongoDB Shell from the tools section at the following link:Mongo Shell
-
Extract the downloaded shell folder, locate the
mongosh
application, and paste it to the following location:Program Files
->MongoDB
->bin
.- You will find the mongosh application inside the
bin
folder]
- You will find the mongosh application inside the
-
Add the path of the location where you pasted the
mongosh
application to your system's environment variables. -
In a separate terminal, run the
mongod
command to start the local instance of the database. -
Create a folder named "data" in the C drive and within it create a new folder named "db".
-
Open a terminal and run the
mongosh
command in the terminal you will get the connection string. In this case the Connection String is:mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.6.2
-
In the
.env
file of Talawa-API, add the connection string to theMONGO_DB_URL
section.$ mongosh Current Mongosh Log ID: e6ab4232a963d456920b3736 Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.6.2 Using MongoDB: 6.0.4 Using Mongosh: 1.6.2 For mongosh info see: https://docs.mongodb.com/mongodb-shell/ ... ... ... ...
-
Here's the procedure to set up Redis.
In the .env
file, you should find three variables: REDIS_HOST
, REDIS_PORT
, and REDIS_PASSWORD
. These environment variables will contain the necessary information for your codebase to connect to a running redis-server
.
In both scenarios (Linux or WSL post-installation), the variable values should be configured as follows:
REDIS_HOST
= localhostREDIS_PORT
= 6379 Note: This default port is used by theredis-server
. However, if yourredis-server
operates on a different port, you must provide that port number.REDIS_PASSWORD
should be left empty, as passwords are unnecessary for local connections.
To begin, you must register for a free account on Redis Cloud. Following this step, you can proceed by selecting a database from the free tier, which comes with a 30MB data storage limit. Once completed, you can then access your Database by navigating to the Databases
section. Here, you will find the option to view the overall settings of your free instance.
Here are the configuration details:
REDIS_HOST
= ThePublic endpoint
assigned to your Database, excluding the.com
. It will resemble something likeredis-13354.c169.us-east-1-1.ec2.cloud.redislabs.com
. The numerical value following this address is the port number.REDIS_PORT
= The number provided in thePublic Endpoint
after the colon (:
), for instance:13354
.REDIS_PASSWORD
= TheDefault user password
located in the Security Section.
The user with the email address set with this parameter will automatically be elevated to Super Admin status on registration.
- When installing, set this to the email address of the person you want to be the very first Super Admin.
- This will usually be the email address of the person installing the software.
- If this is not set you will not be able to administer the application.
If you don't set this parameter, then you'll need to follow the Manually Adding The First Super Admin User
process discussed later in this document.
Set this value in the event that you need to elevate any of your users to be a Super Admin.
NOTE It is STRONGLY advised that you remove the email address once the initial installation and setup has been done.
You need to have a google
account to follow the following steps.
We use reCAPTCHA
for two factor authentication (2FA). Follow these steps:
-
Visit the reCAPTCHA Key Generation URL.
-
Click on
Submit
button. -
Copy the generated
Secret Key
to variable namedRECAPTCHA_SECRET_KEY
in.env
file. -
NOTE: Save the generated
Site key
as it will be used intalawa-admin
.
NOTE: ReCAPTCHA is a type of 2FA, so your Google account needs to have two factor authentication set up for the following steps to work. Make sure this is done before proceeding
The MAIL_USERNAME and MAIL_PASSWORD parameters are required to enable an app to access 2FA features. This is how to know what they should be.
- Go to your google account page.
- Search for
App Passwords
in theSearch Google Account
search bar and select it. - Click on
create a new app-specific password
and entertalawa
as the custom name and press theCreate
button. - Copy the 16 character generated app password to the variable named
MAIL_PASSWORD
in.env
file. - Copy your usual gmail address to the variable named
MAIL_USERNAME
in.env
file.
For more info refer to this Google Answer.
For using SMTP server instead of Gmail, following steps need to be followed:
- Set the
IS_SMTP
variable totrue
for exampleIS_SMTP=true
- Go to your your SMTP server, and note the following variables:
SMTP_HOST=your-smtp-server-hostname
SMTP_PORT=your-smtp-server-port
SMTP_USERNAME=your-smtp-username
SMTP_PASSWORD=your-smtp-password
SMTP_SSL_TLS=true-or-false
For example:
SMTP_HOST=smtp.hostgator.com
SMTP_PORT=465
SMTP_USERNAME=example@website.com
SMTP_PASSWORD=
SMTP_SSL_TLS=true
For more information on setting up a smtp server, here's a useful article
To use MinIO with Talawa-API, you need to set up the following environment variables in your .env file:
MINIO_ENDPOINT=<minio-endpoint>
MINIO_ROOT_USER=<you-minio-user>
MINIO_ROOT_PASSWORD=<your-minio-password>
MINIO_BUCKET=<your-minio-bucket-name>
MINIO_DATA_DIR=<path-to-local-data-directory>
For example:
MINIO_ENDPOINT=http://localhost:9000
MINIO_ROOT_USER=minioadmin
MINIO_ROOT_PASSWORD=minioadminpassword
MINIO_BUCKET=talawa-bucket
MINIO_DATA_DIR=./data
Here are the configuration details:
MINIO_ENDPOINT
: URL where MinIO is hosted. Use http://minio:9000 for Docker setups, or http://localhost:9000 otherwise.
MINIO_ROOT_USER
: Root username for authenticating and managing MinIO resources.
MINIO_ROOT_PASSWORD
: Root password for authenticating with MinIO. Must be kept secure.
MINIO_BUCKET
: Name of the default bucket for storing files in MinIO.
MINIO_DATA_DIR
: Specifies the directory path where MinIO stores data locally. It is used to define the storage location for the MinIO server on the host machine.
- This is an optional setting
- You can set up and customize logs by configuring the following parameters
The parameter COLORIZE_LOGS
is a boolean field and can be set to true or false. It customizes the log colorization formats displayed in console. You can set the value in .env
file as
COLORIZE_LOGS = false
If the parameter value is set to true
, you should be able to see colorized logs in console, or else logs will display in the console's default simple format.
There are different logging levels that can be configured by setting this parameter. The severity order of levels are displayed numerically ascending from most important to least important.
levels = {
error: 0,
warn: 1,
info: 2,
http: 3,
verbose: 4,
debug: 5,
silly: 6
}
On setting this parameter value, log messages are displayed in the console only if the message.level
is less than or equal to the LOG_LEVEL
set.
For our application, the most appropriate setting is LOG_LEVEL = info
since most of information logged on the console are error messages, warnings or info texts.
Talawa API contains a sample database importing function which can be used to import sample database.
npm run import:sample-data -- [args]
You can pass the following arguments while running this script.
--format
: Cleans the database before import.- NOTE! Add this flag with caution. It will delete all of the existing data inside the talawa database.
--items=
: Specifies the items to add. The followingitems
can be specified, separated with a comma,
users
: For users collectionorganizations
: For organizations collectionevents
: For events collectionposts
: For posts collection
npm run import:sample-data
: This command will import the complete sample database without removing the existing data.npm run import:sample-data -- --format
: This command will import the complete sample database after removing the existing data.npm run import:sample-data -- --format --items=users,organizations,appUserProfiles
: This command will import the sampleusers
,organizations
andappUserProfiles
collections after cleaning the existing data.npm run import:sample-data -- --items=users,organizations,appUserProfiles
: This command will import the sampleusers
,organizations
ansappUserProfiles
collections without cleaning the existing data.
The sample data contains organizations, users, events and posts. Here are the details for each of organizations and user account.
Password | User Type | Joined Organization | Admin For | |
---|---|---|---|---|
testuser1@example.com | Pass@123 | USER | Angel Foundation | None |
testuser2@example.com | Pass@123 | USER | Angel Foundation | None |
testuser3@example.com | Pass@123 | USER | Angel Foundation | None |
testadmin1@example.com | Pass@123 | ADMIN | Angel Foundation | Angel Foundation |
testadmin2@example.com | Pass@123 | ADMIN | Hope Foundation | Hope Foundation |
testadmin3@example.com | Pass@123 | ADMIN | Dignity Foundation | Dignity Foundation |
testsuperadmin@example.com | Pass@123 | SUPERADMIN | The Unity Foundation | ALL |
There is one post inside the The Unity Foundation
There is one event inside the The Unity Foundation
Talawa-api development server runs two processes simultaneously in the background. They are:
-
GraphQL code generator:
This watches for changes in the graphQL type definition files and generates corresponding typescript types in the background. This results in good code editor experience with typescript. -
Talawa-api server:
This runs talawa-api directly transpiling the typescript files and running them without emitting as javascript files. It also watches for changes in the code files and restarts the server if it detects any changes.
Run the following command to start talawa-api development server:
npm run dev
There are many important URLs for accessing the API
These are some important URLs for coding and troubleshooting :
-
By default talawa-api runs on
port 4000
on your system's localhost. It is available on the following endpoint:http://localhost:4000/
-
If you navigate to the endpoint you and see a
JSON
response like this it means talawa-api is running successfully:{"talawa-version":"v1","status":"healthy"}
-
-
The graphQL endpoint for handling
queries
andmutations
is this:http://localhost:4000/graphql/
-
GraphQL endpoint for handling
subscriptions
is this:ws://localhost:4000/graphql/
The Organization URL for Talawa mobile app developers will depend upon the device on which Mobile app is installed.
If the Talawa Mobile App is installed on Android Virtual Device (AVD), use the following URL:
http://10.0.2.2:4000/graphql
If Talawa Mobile App is installed on a Real Mobile Device, follow the below steps to get URL:
-
Open Command Prompt in Windows, or Terminal in Linux/OSX
-
Enter
ipconfig
(For Windows Users) orifconfig
(For Linux/OSX Users) -
Your Mobile and Computer (On which API server is running) must be on same Wifi Network. Use Mobile Hotspot to connect your computer to internet in case you don't have access to a Wifi Router.
-
Search for the
Wireless LAN adapter Wi-Fi:
and then copy theIPv4 Address
-
Now, use this IP address (
192.168.0.105
in our case) to access the API instance using the following URL pattern:http://{IP_Address}:4000/graphql
For example:
http://192.168.0.105:4000/graphql
The Organization URL for Talawa mobile app developers to use is:
http://localhost:4000/graphql/
There are many ways to access MongoDB.
Open MongoDB Compass and click on "Connect." You will now be able to access the graphical user interface of the local database.
NOTE: You can do the same in macOS and linux with minor tweaks. This has been provided to give a brief overview for beginners to setup their own local instance.
This guide is for VSCode
users to easily manage their MongoDB
databases:
-
Install the offical
MongoDB
extension forVSCode
namedMongoDB for VS Code
. -
Connect your
MongoDB
database to the extension. -
Now you can manage the database you are using for
talawa-api
through this extension withinVSCode
.
You can skip these instructions for now if you don't have running instance of Talawa-Admin.
-
This step is for mandatory Linux specific users others can skip to next step:
- You need to start
mongod
[Mongo daemon process] formongosh
to work use the following commands:- Using the System V init
sudo service mongod start
- Using systemd
sudo systemctl start mongod
- Using the System V init
- To verify whether
mongod
[Mongo daemon process] is running you can use either:- Using the System V init
sudo service mongod status
- Using systemd
sudo systemctl status mongod
- Using the System V init
- You need to start
-
Open MongoDB Compass and click on
Connect
. -
Select your database.
-
Elevate the user status:
-
Open a terminal and run
mongosh
command to open interactive command line interface to work with MongoDB database. -
In the
mongosh
terminal use the following commands to edit theappuserprofiles
collections data:- Find the user:
const currentUser = db.users.findOne({ firstName: '<user's first name>'})
- Elevate permission of this user in its
AppUserProfile
, i.e. setisSuperAdmin
totrue
:db.appuserprofiles.updateOne({ _id_: currentUser.appUserProfileId },{ $set: { isSuperAdmin: true }})
- To verify the details were updated correctly use:
db.appuserprofiles.findOne({ _id_: currentUser.appUserProfileId })
- Find the user:
Note: You can make the edit via any of these two methods.
These are some other factors to consider
If port 4000
is not free on your system you can pass a custom environment variable named PORT
to the script to make it use a different port on your system's localhost. Here's the syntax for it:
PORT=<CUSTOM_PORT_VALUE> npm run dev
where <CUSTOM_PORT_VALUE>
is whatever value you want the PORT
to be.
Whatever you pass will be substituted as the value for port and talawa-api development server on that port.
http://localhost:<CUSTOM_PORT_VALUE>/
For example using this command:
PORT=5000 npm run dev
will make talawa-api accessible on the following endpoint:
http://localhost:5000/
Talawa-api makes use of vitest
to run tests because it is much faster than jest
and more comfortable to work with.
You can run the tests for talawa-api using this command:
npm run test