Backend (Nodejs)
Requirements
Person who has experience to deal with ubuntu server and deploy otherwise you can contact me iam offer best upload experience
Install Node.js (version
v16.x
or to19.x
) and npm. Check the Node.js version usingnode -v
.Install only if you not
docker user
cross-envnpm i -g cross-env
for managing production or development environments and pm2 for manage production deploy bynpm i -g pm2
CLI (npm install -g @nestjs/cli
).Install MongoDB (minimum
v4.4
, recommendedv6
).
.env file
# you can out local url or docker url or url of mongo in another service
DB_URL="YOUR_MONGO_URL"
# Dont update it ever after you set it! if you do all users will logout!!!
JWT_SECRET="STRONG_PASSWORD"
# Dont update it ever after you set it! if you do all users will logout!!!
issuer="your gmail"
# Dont update it ever after you set it! if you do all users will logout!!!
audience="your gmail"
NODE_ENV="production" # dont update it
EDIT_MODE ="false" # set to false
ignoreEnvFile="false" # set to true if you will inject the env values from system os
PORT=80 //exposed port of node js
#Admin panel passwords be carfaul
ControlPanelAdminPassword= "xxxxxxxxxxxxx" # put strong password for admin who can edit and update any thing in the app
ControlPanelAdminPasswordViewer= "xxxxxxxxxx-xxxx" # put strong password for admin that can only read(see ,users data,chats data etc...) he cannot update any thing
isOneSignalEnabled ="false" # set to true if you can provide oneSignalAppId and oneSignalApiKey to enable push by onesignal
isFirebaseFcmEnabled ="false" # set to true if you provide the firebase admin.json file
#set onesignal data if you support it by set isOneSignalEnabled to true
oneSignalAppId="xxxxxxxxx-xxxxx-xxxxx-xxxx-xxxxxxxxx"
#set onesignal data if you support it by set isOneSignalEnabled to true
oneSignalApiKey="xxxxxxxxx"
# SET THE Email data to let use use forget password OTP
EMAIL_HOST="EMAIL HOST FROM THE PROVIDER COMPANY"
EMAIL_USER="YOUR EMAIL USER"
EMAIL_PASSWORD="EMAIL USER PASSWORD"
# SET AGORA API KEYS
AGORA_APP_ID=""
# Get this from agora app console `Primary Certificate` value
AGORA_APP_CERTIFICATE=""
privacy-policy
- You can update your privacy privacy page in the source code inside
http://localhost:3000/privacy-policy.html
this will be theprivacy-policy
of your app- You can edit it inside
public/privacy-policy.html
- You can edit the home inside
public/home.html
you can access ithttp://localhost:3000
firebase admin file
- Make sure the firebase account is the same as the one used in flutter app.
- To ensure chat notifications work properly, follow this video to
obtain the
firebase.adminsdk.json
file. - Replace the existing
firebase.adminsdk.json
file with your new one.
Setting Up Agora for Your Application
This guide will walk you through setting up Agora for your application, retrieving the necessary keys, and ensuring proper configuration to enable live calls.
- Step 1: Create and Configure Your Agora Project
Log in to the Agora Console
- Navigate to the Agora Console.
- Log in or create a new account if you don’t have one.
Create a New Project
- Go to the Projects section.
- Click Create to add a new project.
- Provide a name for your project and ensure you select the Live mode to enable live broadcasting features.
Enable Primary Certificate
- After creating your project, go to the Project Management page.
- Locate your project and click on Edit.
- Ensure that the Primary Certificate is enabled. This is essential for secure communication and authentication.
- Step 2: Retrieve Your Agora Keys
Locate Your Project Keys
- In the Agora Console, navigate to the Project Details section of your newly created project.
Get the
AGORA_APP_ID
- Copy the
App ID
value. This is your unique project identifier.
- Copy the
Get the
AGORA_APP_CERTIFICATE
- Scroll down to find the Primary Certificate section.
- Copy the value under Primary Certificate. This will be used for token generation and secure authentication.
Important Note:
Ensure you handle the Primary Certificate
securely and never expose it publicly to prevent unauthorized access to your application.
- Step 3: Update Your
.env
File
Open the
.env
file in your project’s root directory.Add or update the following keys with the values you retrieved from the Agora Console:
AGORA_APP_ID=your_agora_app_id_here
AGORA_APP_CERTIFICATE=your_agora_certificate_hereEnsure the values match exactly with those from the Agora Console. Any mismatch will prevent calls from working correctly.
- Step 4: Ensure Consistency in Your Flutter App
If you are using Flutter for the frontend,
inside the flutter
s_constants
file the value ofagoraAppId
Obtaining OneSignal Keys
Create a Firebase account and follow this video to obtain OneSignal keys.
Update the following fields with your OneSignal keys:
oneSignalAppId="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx"
oneSignalApiKey="xxxxxxxxxxxx"
Running the Code (Without Docker)
- You should be familiar with ubuntu server setup
- Install ubuntu server v 20.* and later
- Open a terminal in the
backend
root folder. - Run
npm i
ornpm i --force
if issues occur. - Generate a
dist
foldernpm run build
. - Run
npm run start:prod
for live console logs for just make sure your server is configure well - if you run in production mode. in your vps server then you should
- then stop and run this run
pm2 start ecosystem.config.js --only normal --env production
.for background serve - to see logs run
pm2 logs
- If you see
app run in production,
your code is production-ready. - Access the development server at
localhost:80
and production server at port80
Update the port in.env.production
if necessary. - Update the
PORT
in the.env
file if using Docker, and ensure you update the environment variable in the OS (env). - you need to install
nginx
and connect domain to your server for security and more speed! - dont forget to add the websocket support for nginx while you configure it
- inside the location of your server block don't forget to add this to enable websocket support
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
Deploy web
- run the flutter code to build the web version inside the
super_up_app
folder - run this code
flutter build web --web-renderer html
- now you can find the html folder inside the build folder you need to upload it to your server
- your server can your vps server you can use nginx to deploy your web code and admin code
Deploy admin
- run the flutter code to build the web version inside the
super_up_admin
folder - run this code
flutter build web --web-renderer html
- now you can find the html folder inside the build folder you need to upload it to your server
- your server can your vps server you can use nginx to deploy your web code and admin code
Running the Code (With Docker)
- Install Docker and Docker Compose.
- update
.env.production
this keysDB_URL=
frommongodb://127.0.0.1:27017/super_up
toDB_URL=mongodb://myuser_xxx:mypassword_xxx@mongo:27017/super_up?authSource=admin
- Run the
Dockerfile
if Docker is already installed on your system. Note that this only sets up v_chat_sdk and doesn't include MongoDB or Redis. You need to manage these separately OR. - Use a
compose file
witch manage all dependency together. - Run
docker-compose up
to start the containers and view logs, or rundocker-compose up -d
to run in the background.
Running the Code (With Pm2)
- pm2 is a popular framework for run the nodejs applications in background with high performance
- You need first to install it by
npm install pm2@latest -g
- You run the app is already ready to run with pm2 by run
npm run pm2
- To see the logs in real time you can run
pm2 logs
AuthKey.p8
- This key is required to make calls for ios VOIP ring you need to get it from apple
Common Errors
If you encounter the error
ERROR [ExceptionHandler] Configuration key "JWT_SECRET" does not exist
, it means NestJS cannot read your.env.production
file.- To fix this, ensure you have injected the environment variable or that
.env.production
exists in the root of the project. It may be ignored by .git.
- To fix this, ensure you have injected the environment variable or that
If you see the error
The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services
,it means you have enabled FCM but have not configured it.
Iam offer paid full server side setup See Plans