After developing my information system using Sveltekit and setting up the server with Ubuntu 22.04 OS, PM2 as the process manager, and running the app on Node.js, I followed the Sveltekit documentation to deploy the app for a node adapter. Below is my svelte.config.js
code:
import adapter from '@sveltejs/adapter-node';
import { vitePreprocess } from '@sveltejs/kit/vite';
import path from 'path';
/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: vitePreprocess(),
kit: {
adapter: adapter({
out: 'build',
precompress: false,
envPrefix: '',
polyfill: true
}),
csrf: {
checkOrigin: false,
},
alias: {
'$src': path.resolve('./src')
}
},
vitePlugin: {
inspector: false
}
};
export default config;
Once built, I simply run the command npm run preview
to start the app. To integrate with PM2, I created an ecosystem.config.cjs
file for easy management. Here's the configuration:
module.exports = {
apps: [
{
name: "app_sistamu",
script: "npm",
args: "run preview -- --host --port 8080",
watch: false,
instances: "max",
exec_mode: "cluster"
},
{
name: "app_sistamu_DEV",
script: "npm",
args: "run dev -- --host --port 5173",
out_file: "/dev/null",
watch: false
}
],
};
To finalize deployment, I merge changes from development to master branch with subsequent commands:
git merge -m "Merging branch development to master" development; npm install; npm run build; pm2 reload ecosystem.config.cjs --only app_sistamu
Although this process works well, rebuilding the app and reloading PM2 may briefly disrupt user interaction due to a 502 Bad Gateway error during the build phase. However, once completed, the app functions normally again.
This leads me to question how to streamline the deployment process without affecting user experience?