Skip to content

EC2 Server Setup Guide — app.intecoglogistech.com

Full setup steps for deploying the monorepo backend on a fresh Ubuntu EC2 instance.


1. Install nginx

bash
sudo apt update
sudo apt install nginx -y

2. Configure nginx

bash
sudo nano /etc/nginx/sites-available/app.intecoglogistech.com.conf

Paste:

nginx
server {
    server_name app.intecoglogistech.com;

    location / {
        proxy_pass http://127.0.0.1:3500;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_cache_bypass $http_upgrade;
    }

    listen 80;
}

Enable and reload:

bash
sudo ln -s /etc/nginx/sites-available/app.intecoglogistech.com.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

3. Install SSL (Certbot)

bash
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d app.intecoglogistech.com

4. Install Node.js via nvm

bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc

nvm install 22.13.1
nvm use 22.13.1
node -v   # confirm v22.13.1

5. Install pnpm and PM2 globally

bash
npm install -g pnpm
npm install -g pm2

6. Clone the repository

bash
cd /home/ubuntu
git clone git@github.com:errorenthusiast99/l-monorepo.git
cd l-monorepo

7. Install dependencies and build

bash
pnpm install --frozen-lockfile
pnpm --filter @my-app/shared build && pnpm --filter @my-app/backend build

8. Install Puppeteer + Chrome (for PDF report generation)

bash
# Install puppeteer in workspace root
pnpm add -w puppeteer

# Download Chrome browser
pnpm exec puppeteer browsers install chrome --force

Install required Ubuntu system libraries for Chrome:

bash
sudo apt-get install -y \
  libnspr4 libnss3 libasound2 libatk1.0-0 libatk-bridge2.0-0 \
  libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 \
  libxfixes3 libxrandr2 libgbm1 libpango-1.0-0 libcairo2 \
  libatspi2.0-0 libxshmfence1

Verify Chrome is ready:

bash
ldd ~/.cache/puppeteer/chrome/linux-*/chrome-linux64/chrome | grep "not found"
# Should print nothing

9. Create .env file

bash
nano /home/ubuntu/l-monorepo/apps/backend/.env

Add all required secrets (never commit this file):

bash
NODE_ENV=production
PORT=3500
MONGODB_URI=...
JWT_SECRET=...
JWT_REFRESH_SECRET=...
AWS_REGION=...
AWS_ACCESS_KEY_ID=...
AWS_SECRET_ACCESS_KEY=...
S3_BUCKET_NAME=...
FROM_EMAIL=...

10. Start with PM2

The ecosystem.config.cjs is already in the repo root. Start it:

bash
# First-time start
pm2 start ecosystem.config.cjs

# Save PM2 process list to survive reboots
pm2 save
pm2 startup   # follow the printed command to enable on boot

For subsequent deploys (zero-downtime reload):

bash
pnpm --filter @my-app/shared build && pnpm --filter @my-app/backend build
pm2 reload prod-logistech --update-env

Or use the root script:

bash
pnpm deploy:backend          # build + reload (normal deploys)
pnpm deploy:backend:fresh    # build + start (first-time or ecosystem.config.cjs changed)

11. Verify everything is running

bash
pm2 status
pm2 logs prod-logistech --lines 50
curl http://localhost:3500/api/v1/auth/health   # or any health check route

Key Details

ItemValue
Server path/home/ubuntu/l-monorepo
PM2 process nameprod-logistech
Backend port3500
Domainapp.intecoglogistech.com
nginx proxies tohttp://127.0.0.1:3500
Node version22.13.1
PM2 configecosystem.config.cjs (repo root)

Intecog Logistech IoT Monitoring Platform