Deploy a mern app on server
To build your frontend using Vite, follow these steps:
1. Install Dependencies
If you haven't already installed dependencies, run:
npm install
or
yarn install
or
npm install
2. Build the Frontend
Run the build command:
npm run build
or
yarn build
or
npm build
This will generate a dist/
folder containing your production-ready files.
3. Serve the Built Files (Optional)
To preview the build locally, use:
npm run preview
Vite will serve the built project on a local development server.
4. Deploy the Frontend
Since you're hosting the frontend on app.flipchat.link
, you need to:
Upload the
dist/
folder to your server.Configure Nginx to serve it properly.
1. Install Dependencies
If you haven't already installed dependencies, run:
npm install
or
yarn install
2. Set Up Environment Variables
Make sure you have a .env
file in your project directory with the necessary environment variables (e.g., database connection, API keys, JWT secrets, etc.).
Example:
PORT=5000
MONGO_URI=mongodb://localhost:27017/flipchat
JWT_SECRET=your_secret_key
RAZORPAY_KEY_ID=your_key_id
RAZORPAY_KEY_SECRET=your_key_secret
3. Run the Backend in Development Mode
For development with automatic restarts:
npm run dev
This runs the backend using nodemon
, which automatically restarts when file changes are detected.
For a normal run:
npm start
4. Deploying the Backend (I used this one)
If you're deploying on your Hostinger VPS:
Make sure Node.js and
pm2
(for process management) are installed:npm install -g pm2
Start the server with PM2:
pm2 start server.js
Save the PM2 process list:
pm2 save
Set up Nginx as a reverse proxy (if not already configured).