Local Computer

POS OS - Setup Guide for Local Computer - Windows

This guide will walk you through the process of setting up the POS OS software on a local Windows computer. It includes installing the required software and configuring the POS application.

Prerequisites

  • A Windows machine with administrator privileges.

Step 1: Install Node.js, npm, yarn and PM2

  1. Download the Node.js for Windows from https://nodejs.org/en/download/ (opens in a new tab). (LTS - windows installer - 64bit)
  2. Run the installer and follow the prompts to install Node.js and npm.
  3. Open a command prompt or PowerShell with administrator privileges.
  4. Install yarn globally by running the following command:
npm install --global yarn

You can check (whether it is installed correctly) your Node.js version by running node -v and your npm version by running npm -v and your yarn version by running yarn -v.

  1. Install PM2 globally by running the following command:
yarn global add pm2

Note: PM2 is a process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks. It's great for production environments, helps you to keep applications online 24/7, and can help you to build a resilient architecture with scalability. Know more about PM2 here (opens in a new tab).

Step 2: Install PostgreSQL Database

  1. Download the PostgreSQL installer for Windows from https://www.enterprisedb.com/downloads/postgres-postgresql-downloads (opens in a new tab). (Windows x86-64)
  2. Run the installer and follow the prompts to install PostgreSQL. Remember the password you set for the postgres user during the installation process.

Step 3: Configure the backend (Express/Node.js)

  1. Unzip the zip file you downloaded from the Codecanyon.
  2. Navigate to the backend folder using command prompt/powershell:
cd ERO-OS-application\POS_OS_Backend
  1. Install dependencies by running the following command on the command prompt:
yarn
  1. Configure the .env file according:

Open/create the .env file using VS Code or any other text editor and copy the following content into the .env file:

JWT_SECRET = <your_secret>
DATABASE_URL = "postgresql://<postgres_username>:<postgres_user_password>@localhost:5432/<postgres_database_name>"
HOST = <your_host>
NODE_ENV = <environment_name>

replace <your_secret> with a secure secret (e.g., JWT_SECRET = mysecret)

replace <postgres_username> with the username, <postgres_user_password> with the password, <postgres_database_name> with the database name you created in Step 2 (e.g., postgresql://postgres:123456@localhost:5432/pos)

replace <your_host> with the domain or IP address (e.g., http://localhost)

replace <environment_name> with the environment name (e.g., NODE_ENV = development).

  1. Run the migration and seed the database one by one using the following commands:
yarn prisma migrate dev

press enter when it asks for.

yarn prisma

If auto seeding doewn't work, run the following command:

yarn prisma db seed

this will seed the database with the default data (with admin login name and password). If it doesn't run properly you can't login.

If it runs twice, it will throw an error. Then you can delete the migrations folder from /POS_OS_Backend/prisma/ and run the above commands again.

  1. Navigate to the root of POS_OS_Backend where server.js is located and Start the backend server from command prompt:
pm2 start server.js --name POS_backend

Here POS_backend is the name of the process that you want to give to the backend server. You can give any name you want.

Step 4: Configure the frontend (React.js)

  1. Navigate to the frontend folder using command prompt/powershell:
cd ERO-OS-application\POS_OS_Frontend
  1. Install dependencies by running the following command on the command prompt:
yarn
  1. Configure the .env file according:

Open/create the .env file using VS Code or any other text editor and copy the following content into the .env file:

REACT_APP_API = 'http://<your_host>:5000/'

replace <your_host> with the local host (e.g., http://localhost:5000/v1/)

  1. Run the frontend server using PM2 process manager by running the following command:
pm2 start yarn --name POS_frontend -- start

Here POS_frontend is the name of the process that you want to give to the frontend server. You can give any name you want.

Now, your POS software should be accessible at http://localhost:3000/. If you encounter any issues, make sure to check the logs and ensure that all services are running correctly.

Change the backend file to accept the request from your frontend

  1. Nvigate to the backend folder: cd POS-OS-application/POS_OS_Backend
  2. Open the file app.js using VS Code or any other text editor.
  3. Find the variable allowedOrigins and add your frontend domain and port in the allowedOrigins variable as an array element and save the file:
// holds all the allowed origins for cors access
 
let allowedOrigins = [
"http://localhost:5000",
"http://<your_frontend_domain>:<your_frontend_port>",
];

replace <your_frontend_domain> with your frontend domain and <your_frontend_port> with your frontend port (e.g., "http://localhost:3000").

  1. Restart the backend server by running the following command:
pm2 restart POS_backend

replace POS_backend with the name of the process you gave to the backend server earlier in step 3.6


Extras: for power users

Restart the server

If you change any file in the backend or frontend, you need to restart the server. To restart the server, run the following command:

pm2 restart <process_name>

replace <process_name> with the name of the process you gave to the backend or frontend server (e.g., pm2 restart POS_backend).

or you can restart all the processes by running the following command:

pm2 restart all

Stop the server

To stop the server, run the following command:

pm2 stop <process_name>

replace <process_name> with the name of the process you gave to the backend or frontend server (e.g., pm2 stop POS_backend).

or you can stop all the processes by running the following command:

pm2 stop all

Delete the server

To delete the server, run the following command:

pm2 delete <process_name>

replace <process_name> with the name of the process you gave to the backend or frontend server (e.g., pm2 delete POS_backend).

or you can delete all the processes by running the following command:

pm2 delete all

Monitor the server

To monitor the server and logs, run the following command:

pm2 monit

Check all the processes

To check all the processes, run the following command:

pm2 list

You have successfully deployed your app to your local computer
🎉 Congratulations! 🎉