How to host SvelteKit SSR apps (GDPR-compliant)?
Tags: sveltekit, node, javascript, svelte
Published: 2022-10-22 09:31:11

In a recent [article](https://dev.to/mandrasch/rich-harris-explains-why-sveltekit-pushes-for-server-side-rendering-and-against-spa-5flj) I tried to summarize Rich Harris arguments why SvelteKit pushes for Server Side Rendering and against Single Page Applications (SPA) / Client Side Rendering (CSR). In short: It's better for SEO, performance and resilience. One advice by Rich was: Don't use Single Page Applications unless you have a very good reason. 

_As always: it depends on your project case though. If your site content doesn't change often, a static SvelteKit site via [adapter-static](https://kit.svelte.dev/docs/adapters#supported-environments-static-sites) is an option as well. But if you pull in recent blog posts for example, [SvelteKit adapter-node (SSR)](https://kit.svelte.dev/docs/adapters#supported-environments-node-js) should be considered. The awesome thing about this: You don't have to worry how to start the build process when content changes. This is needed for static generated sites, otherwise they don't have the latest content (obviously). With SSR you always fetch the latest data._

### VPS hosting 

Following up on that, I recently found some great articles about SvelteKit hosting on Virtual Private Servers (VPS):

- [Deploying SvelteKit with NodeJS to a (Hetzner) Server Using Gitlab and PM2](https://abyteofcoding.com/blog/deploying-sveltekit-with-nodejs-pm2-to-server/) by abyteofcoding.com
- [SvelteKit Node App Deploy: Linux Cloud Hosting (Linode)](https://rodneylab.com/sveltekit-node-app-deploy/) by rodneylab.com

These articles give a good insight about what is needed behind the scenes. I'm personally not a skilled server admin and have so much respect for all the IT girls and guys taking care of servers and networks every day. I have no deep knowledge about this, but I think it is good to understand the basics.

So let's briefly explore pm2 and then move on to other hosting options. 

### What is pm2? 

"PM2 is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks." ([pm2](https://www.npmjs.com/package/pm2))

{%youtube https://www.youtube.com/watch?v=ebdKIU6SDHI %}

Other similiar tools are [nodemon](https://www.npmjs.com/package/nodemon) and [supervisor](https://www.npmjs.com/package/supervisor). 

You could run these at well on a Raspberry Pi for example.

### "But I don't want to fiddle around on the terminal!?"

A great service type I recently discovered are server management tools. They offer simple dashboards for configuring the virtual private servers mentioned above. And most of them support NodeJS as well:

- https://ploi.io/nodejs
- https://cleavr.io/nodejs/
- I found a [gist for Laravel Forge](https://gist.github.com/jpcaparas/ded09732f756db155e97216aa430d676) as well

The great thing about them is that you can connect various VPS providers, so you're not locked in to one price model or one hosting provider alone, here is a screenshot of Ploi: 

![Screenshot of plois server creation dialog](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6hklzu8oe8byobsgdsyn.png)

### Full service hosting providers

There are also providers who take care of hosting, no VPS needed. Here are some examples, render.com even offers a free tier (limited by time of usage):

- https://render.com/docs/deploy-sveltekit
- https://railway.app/new/template/svelte-kit
- https://northflank.com/

### Even more easy: Integrated platform support

As [SvelteKit docs](https://kit.svelte.dev/docs/adapters#supported-environments) state, there is also out-of-the-box support for these hosting providers:

- [Cloudflare Pages](https://pages.cloudflare.com/) via adapter-cloudflare
- [Netlify](https://www.netlify.com/) via adapter-netlify
- [Vercel](https://vercel.com/) via adapter-vercel

But ...

### SvelteKit, European Union and GDPR hurdles

.. as much as I'm impressed by Vercels dashboard and ease of use of all these full hosting services, my personal opinion is the following:

If SvelteKit (and other similiar frameworks like Astro) want to succeed in the European Union, NodeJS hosting must become much more simple: Simple as todays PHP hosting.

I can go to a various EU webspace providers like Hosteurope, Strato, Ionos, All-Inkl, Manitu, etc. and get decent PHP hosting for multiple sub-sites + databases starting at 2,50 € a month, including unlimited bandwith.  

The most important thing: The servers are fully located in the European Union, I have no struggles with GDPR-concerns and [the invalidated privacy shield for EU-US-data-transfer (Schrems II ruling)](https://www.theverge.com/2020/7/16/21326795/eu-us-personal-data-transfer-privacy-shield-invalidated-sccs-upheld).

The good news: 

One german hosting company pioneering this is [Mittwald](https://www.mittwald.de/faq/tools-cms/software/node-js-app-einrichtung). They introduced NodeJS hosting for additional 9€/month on their product agency server.

Personally I hope that others will follow, which would it make it much much more easier to introduce SvelteKit into existing tech stacks in my opinion. If it's just another click on a button "Add NodeJS app" on the current hosting provider, there is no lengthy discussion needed for introducing something new (which might even be hard to integrate because of GDPR-compliance). 

Especially because of the recent automated mass law suit wave due to embedded google fonts (https://www.patrickriedl.at/wave-of-lawsuits-in-austria-due-to-use-of-google-fonts/), stakeholders might be more sensitive about these concerns.

### What have I missed? What do you prefer?

Happy to hear your comments about your preferred hosting method for SvelteKit SSR (or NodeJS SSR in general)! Also please let me know if I missed a service! Thanks! 🤗