dr.

Writing / JavaScript & the browser · · 1 min read

Deploying svelte kit application

With the announcement of the stable release of sveltekit 1.0, there are many movements going around in svelte space and I have been exploring svelte and sveltekit for a while. Deploying a sveltekit app is not explained anywhere properly. So, in this blog, I will be explaining how to deploy a sveltekit application.

Prerequisites

  • A sveltekit application.

  • A server to host or an instance to deploy(digital ocean, AWS ec2, etc).

Once you are ready with both of these, let’s get started and deploy our sveltekit application.

svelte.config.js

import adapter from '@sveltejs/adapter-auto';

/** @type {import('@sveltejs/kit').Config} */
const config = {
	kit: {
		adapter: adapter({ out: 'directory-name' }),
	}
};

export default config;
  • Run npm run build

  • Check for errors if any.

  • Download [pm2](https://pm2.keymetrics.io/) for running node process in the background.

  • Travel to the directory where the build has been created.

  • Run pm2 start index.js --name <NAME>

  • Your site will start running on IP:3000.

  • If you want to change PORT, you can pass the HOST and PORT variables like this HOST=127.0.0.1 PORT=4000 npm run build

NOTE: To check logs go to pm2 logs <NAME>

Thanks for reading the blog. If you like it, don’t forget to hit the clap icon. If you need any help leave a comment below.

Written by Dikshant Rajput, AI and full-stack engineer. Also published on Medium. Questions? Ask my AI version or get in touch.