Last year around summertime I got to play around with Deno and it was lots of fun 😀 I mostly made simple server scripts to serve up static sites. The most Deno code I wrote was rewriting my dotfiles from Ruby to Typescript.
It was interesting and soon I would like to try out more things so this post is for myself and anyone else out there who wants to deploy Deno on a traditional Linux distribution like Ubuntu or some other Linux distro.
Heads up as of this writing, the current version of Deno is v0.40.0. The project is not yet considered production-ready so keep that in mind when you want to expose your app to the internet. If you are receiving traffic on the internet there might be bugs that people could exploit.
What is Deno?
deno might not work since a rapper uses that name 😜
In this setup, I will just assume you are using some proxy server and will only focus on the systemd specific bits. Depending on what kind of application you are running you might want to consult the full systemd documentation. I also recommend running the app as a dedicated user this way you can restrict it even more (please don't use root 😅).
Before we actually move on to installing Deno, let's get curl and unzip.
curl is used to get the install script and
unzip is used when deno is downloading dependencies (I think 🙃).
sudo apt-get update sudo apt-get install -y curl unzip
The easiest way to get Deno on your server is the official install script
curl -fsSL https://deno.land/x/install/install.sh | sh
Adding the Service file
Great, now that you have Deno in place, you need to tell systemd about the application. So first create the service file we will be using, just replace
my-cool-thing with your app name.
sudo touch /etc/systemd/system/my-cool-thing.service
Use this template to set the values (change out the relevant fields or delete)
[Unit] Description=my-cool-thing.io - doing cool things Documentation=https://my-cool-thing.io/docs After=network.target [Service] Type=simple User=my-cool-thing-user WorkingDirectory=/home/my-cool-thing-user/code ExecStart=/home/my-cool-thing-user/.deno/bin/deno run --allow-read --allow-net my-cool-thing-main.ts Restart=on-failure [Install] WantedBy=multi-user.target
Then enable and start it
sudo systemctl enable my-cool-thing sudo systemctl start my-cool-thing
Bam, now you have your service all wired up and ready.
If you end up with issues, check the logs
One common mistake I have seen is forgetting to pass the right permissions, but those are easy to spot by manually running the start command
deno run my-cool-thing-main.ts
I’m Alexander and work as a Web Developer at Scrimba - The mind-blowing way to learn how to code. This post is part of my personal weekly challenge of writing 256 words per week to improve my writing on technical topics.
I hope you found it useful. Thank you for reading.
Top comments (0)