INVENTORY OS - Setup Guide for Local Computer - Windows
This guide will walk you through the process of setting up the INVENTORY OS software on a local Windows computer. It includes installing the required software and configuring the INVENTORY application.
Prerequisites
- A Windows machine with administrator privileges.
Step 1: Install Node.js, npm, yarn and PM2
- Download the Node.js for Windows from https://nodejs.org/en/download/ (opens in a new tab). (LTS - windows installer - 64bit)
- Run the installer and follow the prompts to install Node.js and npm.
- Open a command prompt or PowerShell with administrator privileges.
- Install
yarnglobally by running the following command:
npm install --global yarnYou 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.
- Install PM2 globally by running the following command:
yarn global add pm2Note: 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
- Download the PostgreSQL installer for Windows from https://www.enterprisedb.com/downloads/postgres-postgresql-downloads (opens in a new tab). (Windows x86-64)
- Run the installer and follow the prompts to install PostgreSQL. Remember the
passwordyou set for thepostgresuser during the installation process.
Step 3: Configure the backend (Express/Node.js)
- Unzip the
zipfile you downloaded from the Codecanyon. - Navigate to the backend folder using command prompt/powershell:
cd ERO-OS-application\INVENTORY_OS_Backend- Install dependencies by running the following command on the command prompt:
yarn- 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/inventory)
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).
- Run the migration and seed the database one by one using the following commands:
yarn prisma migrate devpress enter when it asks for.
yarn prismaIf auto seeding doewn't work, run the following command:
yarn prisma db seedthis 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 /INVENTORY_OS_Backend/prisma/ and run the above commands again.
- Navigate to the root of
INVENTORY_OS_Backendwhere server.js is located and Start the backend server from command prompt:
pm2 start server.js --name INVENTORY_backendHere INVENTORY_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)
- Navigate to the frontend folder using command prompt/powershell:
cd ERO-OS-application\INVENTORY_OS_Frontend- Install dependencies by running the following command on the command prompt:
yarn- 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/)
- Run the frontend server using PM2 process manager by running the following command:
pm2 start yarn --name INVENTORY_frontend -- startHere INVENTORY_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 INVENTORY 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
- Nvigate to the backend folder:
cd INVENTORY-OS-application/INVENTORY_OS_Backend - Open the file
app.jsusing VS Code or any other text editor. - Find the variable
allowedOriginsand add your frontend domain and port in theallowedOriginsvariable 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").
- Restart the backend server by running the following command:
pm2 restart INVENTORY_backendreplace INVENTORY_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 INVENTORY_backend).
or you can restart all the processes by running the following command:
pm2 restart allStop 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 INVENTORY_backend).
or you can stop all the processes by running the following command:
pm2 stop allDelete 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 INVENTORY_backend).
or you can delete all the processes by running the following command:
pm2 delete allMonitor the server
To monitor the server and logs, run the following command:
pm2 monitCheck all the processes
To check all the processes, run the following command:
pm2 listYou have successfully deployed your app to your local computer
🎉 Congratulations! 🎉