Skip to content

Documentation

Getting Started

Introduction

This guide will walk you through setting up the project, including the initial setup, server requirements, and how to run both the backend and frontend for your application. Additionally, it covers configuring Nginx as a reverse proxy and virtual host to handle API requests from your Node.js server and serve your frontend application.

Server Requirements

Before you start, make sure your server meets the following requirements:

Node.js: Version 18.0.0 or higher
PostgreSQL: Version 13 or higher
NPM: Version 7.0.0 or higher
Nginx: Version 1.22 or higher

Setting Up

So, you’ve purchased and downloaded the Fetchiyo Ecommerce script. Great! Now it’s time to get it up and running on your web server.

Before you start, make sure you’ve extracted the project files and have the project folder ready.

Uploading the Project to your Web Server

Upload the Project Folder

Use a file transfer client like FileZilla or WinSCP to upload the fetchiyo project folder to your web server.

Rename the Project Folder

Rename the folder to match your domain or project name:

mv fetchiyo myProject
cd myProject

Next, initialize the project

npm init -y

Install Dependencies

Install both frontend and backend dependencies:

npm install
npm install express body-parser cookie-parser cors dotenv pg

Configure Environment Variables

Create a .env file

Create a .env file in the src directory of your project.

Add the following configuration and replace the placeholder values with your actual values:

SITE_NAME=myProject
DB_USER=DB_USER
DB_PASSWORD=DB_PASSWORD
DB_HOST=localhost
DB_PORT=5432
DB_NAME=DB_NAME
PORT=4002
UPLOAD_PATH=uploads/
INVOICE_PATH=invoices/
HOST=https://example.com
JWT_SECRET=your_jwt_secret_here
FIREBASE_PROJECT_ID=exampleapp
FIREBASE_SERVICE_ACCOUNT_KEY_PATH=/path/to/your/firebase/serviceAccountKey.json
  • SITE_NAME=myProject: Replace myProject with the name of your site.
  • DB_USER=DB_USER: Replace DB_USER with your PostgreSQL database username.
  • DB_PASSWORD=DB_PASSWORD: Replace DB_PASSWORD with your PostgreSQL database password.
  • DB_HOST=localhost: If your PostgreSQL server is on a different host, replace localhost with the appropriate host address.
  • DB_PORT=5432: Replace 5432 if your PostgreSQL server is using a different port.
  • DB_NAME=DB_NAME: Replace DB_NAME with your PostgreSQL database name.
  • PORT=4002: Set the port number for your Node.js server.
  • UPLOAD_PATH=uploads/: Set the path where uploaded files will be stored.
  • INVOICE_PATH=invoices/: Set the path where invoice files will be stored.
  • HOST=https://example.com: Replace https://example.com with your domain or host URL.
  • JWT_SECRET=your_jwt_secret_here: Replace your_jwt_secret_here with the JWT secret you’ll generate below.
  • FIREBASE_PROJECT_ID=exampleapp: Replace exampleapp with your Firebase project ID.
  • FIREBASE_SERVICE_ACCOUNT_KEY_PATH=/path/to/your/firebase/serviceAccountKey.json:Replace /path/to/your/firebase/serviceAccountKey.json with the path to your Firebase service account key file.

This .env file securely stores environment variables like database credentials, server port, file paths, and API keys.

Generating JWT Secret

To generate a JWT secret, follow these steps:

Open Terminal

Access your server’s command line interface.

Generate JWT Secret

openssl rand -hex 64

This command generates a 64-byte hexadecimal string. The output will look something like this:

1e9b5c2bce9d3d4e5f9e2fca3fbd5a9bca1e7c3d78e8c2d5e4f1b0a7c4e5b9c3e

Add to .env File

Open your .env file located in the src directory of your project.

Add the JWT secret value

JWT_SECRET=1e9b5c2bce9d3d4e5f9e2fca3fbd5a9bca1e7c3d78e8c2d5e4f1b0a7c4e5b9c3e

Replace the example string with your generated secret.

Configure Nginx

Nginx is required to set up as a reverse proxy to handle API requests from your Node.js server. Follow these steps to configure Nginx:

Install Nginx

sudo yum install nginx -y

Create and Edit Nginx Configuration

sudo nano /etc/nginx/conf.d/saas.example.com.conf

Add the following configuration:

server {
server_name example.com;

location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://localhost:5173;
proxy_http_version 1.1;
proxy_set_header Connection "";
keepalive_timeout 75s;
keepalive_requests 100;
}

location /api/ {
proxy_pass http://localhost:4002;
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;
proxy_http_version 1.1;
proxy_set_header Connection "";
keepalive_timeout 75s;
keepalive_requests 100;
}

location /admin/api/ {
proxy_pass http://localhost:4002;
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;
proxy_http_version 1.1;
proxy_set_header Connection "";
keepalive_timeout 75s;
keepalive_requests 100;
}

location /uploads/ {
alias /uploads/;
}

listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

server {
if ($host = example.com) {
return 301 https://$host$request_uri;
}

listen 80;
server_name example.com;
return 404;
}

Restart Nginx to apply the configuration:

sudo systemctl restart nginx

Running Your Application

You can run your application persistently using PM2 or nohup.

Running with PM2

PM2 is a process manager that ensures your applications run persistently. Here’s how to set it up:

Install PM2

Install PM2 globally on your server:

sudo npm install -g pm2

Run Node.js Server with PM2

Navigate to the directory containing your server.js file:

cd /path/to/your/myProject/src

Start your Node.js server with PM2:

pm2 start server.js --name my-node-server

Run Project with PM2

Navigate to your project directory:

cd /path/to/your/myProject

Start the project with PM2:

pm2 start npm --name myProject -- run dev

Save PM2 Process List

Save the PM2 process list to ensure processes are restored on reboot:

pm2 save

Set Up PM2 to Start on Boot

Configure PM2 to start on server boot:

pm2 startup

Follow the instructions provided by the pm2 startup command to enable the startup script for your platform.

Additional PM2 Commands

View running processes:

pm2 list

View logs:

pm2 logs

Restart a process:

pm2 restart [name or id]

Stop a process:

pm2 stop [name or id]

Delete a process:

pm2 delete [name or id]

Running with nohup

nohup allows you to run processes in the background and ensures they continue running even if the terminal session is closed.

Run Node.js Server with nohup

Navigate to the directory containing your server.js file:

cd /path/to/your/myProject/src

Run the Node.js server with nohup:

nohup node server.js > server.log 2>&1 &

Run Project with nohup

Navigate to your project directory:

cd /path/to/your/myProject

Run the project with nohup:

nohup npm run dev > dev.log 2>&1 &

Monitor and Manage Processes

Check if processes are running:

ps aux | grep node
ps aux | grep npm

Stop a process:

Find the PID of the process using the above command and then kill it:

kill [PID]

By following these steps, you’ll have your project script up and running, ready to power your own eCommerce store.

If you encounter any issues or need further assistance, please contact support at support@fetchiyo.com.