محمد علي

Deploying a SvelteKit App to CloudPanel (Node.js)

This guide explains how to deploy any SvelteKit app to a CloudPanel Node.js server.


1. Prepare Your SvelteKit App Locally

  • Ensure your app works locally:
  npm install
  npm run build

2. Log in to CloudPanel

  • Access your CloudPanel dashboard in your browser.
  • Go to Sites and create a new site with the Node.js stack.

3. Upload Your Project Files

  • Use SFTP (e.g., FileZilla) or CloudPanel’s file manager to upload your project files to the site’s directory (e.g., /home/cloudpanel/htdocs/your-site).
  • Exclude node_modules and build output directories (see .gitignore).

4. Install Dependencies on the Server

  • SSH into your server:
  ssh cloudpanel@your-server-ip
  • Navigate to your site directory:
  cd /home/cloudpanel/htdocs/your-site
  • Install dependencies:
  npm install

5. Build the App on the Server

  • Run:
  npm run build

6. Configure the Start Script

  • Ensure your package.json has a start script, e.g.:
  "scripts": {
    "start": "node build"
  }

(For SvelteKit, use the correct adapter and entry point, e.g., adapter-node.)


7. Use a Process Manager (Recommended)

  • Install PM2 globally:
  npm install -g pm2
  • Start your app with PM2:
  pm2 start npm --name "your-app" -- start
  • Save the process list:
  pm2 save
  • Your app will keep running even if you close the terminal.

8. Configure CloudPanel

  • In CloudPanel, set the Start Command to npm start or use PM2 as above.
  • Set the correct Node.js version.

9. Restart and Test

  • Restart the app from CloudPanel or PM2.
  • Visit your domain or server IP to verify the deployment.

Notes

  • For static sites, use the build output and serve with a static server.
  • For SvelteKit, use the appropriate adapter (e.g., @sveltejs/adapter-node).
  • Keep your .env files secure and never upload secrets to public repositories.

This guide works for any SvelteKit app. Adjust paths and commands as needed for your project.