Step by step: deploying a Deno app to Netlify
Tags: deno, netlify, deploy
Published: 2023-04-18 23:38:07

by [Peter Ibeabuchi](https://blog.openreplay.com/authors/peter-ibeabuchi)

Deploying an application to a cloud hosting service is essential in bringing the application to life. With the rise of cloud computing, it has become increasingly easier to deploy, run and manage web applications at scale. Cloud hosting services like Netlify provide a platform for hosting web applications, taking care of server management, and providing additional features like custom domains, SSL certificates, and automatic scaling.

In this tutorial, we'll take an in-depth look at deploying Deno apps using Netlify, from setting up a Netlify account to configuring your application and finally deploying it. 


## What is Netlify?

[Netlify](https://www.netlify.com/) is a next-generation automation and web hosting platform that helps enhance developers' productivity. It simplifies the process of deploying and hosting a web app. It offers a range of features, including continuous deployment, automatic optimization, and serverless functions. It is an attractive option for developers who want to focus on writing code and not worry about infrastructure and hosting. 

Why Netlify? Netlify provides a seamless and efficient solution for hosting your Deno web applications. The platform makes it easy to set up custom domains and HTTPS certificates, ensuring that your application is not only accessible but also secure. Also, as mentioned earlier, Netlify helps automate deployment and provides serverless functions, allowing developers to run server-side code without having to manage any infrastructure. And the good part is it is free!

## Setting up Deno

[Deno](https://deno.com/blog) is a JavaScript and TypeScript runtime built on the V8 JavaScript engine and is an alternative to [Node.js](https://nodejs.org/). However, unlike Node.js, it is built using Rust and comes with support for Typescript, and also includes all modules and dependencies by default; hence it doesn't require package managers.

In this tutorial, we will build a simple web app using Deno and deploy our app to Netlify. At the end of this article, you will get a good sense of how to build a Deno app and deploy it to Netlify. 

**Step 1:** To get started, you must first install Deno. Check out the [installation documentation](https://deno.land/#installation) for your device.

**Step 2:** Next, create a new project folder on your device called `deno_project` (or any preferred name) to store all your code. Afterward, open the folder in your code editor.

**Step 3:** Create a new file called `deno.ts` in your project folder. 

**Step 4:** Then write the code below to build a simple Deno app:
```javascript
import { serve } from "https://deno.land/std@0.62.0/http/server.ts";
const s = serve({ port: 8000 });
console.log("Listening on http://localhost:8000/");
for await (const req of s) {
  req.respond({ body: "Welcome to Deno\n" });
}
```
This code sets up a simple HTTP server that will listen on port 8000 and return a "Welcome to Deno" message when accessed. 

 **Step 5:** To run the code, use the command below:
``` 
deno run --allow-net deno.ts
```

 Here is what our app looks like on the local browser:

![-](https://blog.openreplay.com/images/step-by-step--deploying-a-deno-app-to-netlify/images/s_F6DE0ACEA327969C481DF72792C10DDA9ED799626722E4E0B23E741F6EA78AEC_1675844752763_Screenshot+2023-02-08+at+9.24.56+AM.png)


<div style="background-color:#efefef; border-radius:8px; padding:10px; display:block;">
<hr/>
<h3><em>Session Replay for Developers</em></h3> 
<p><em>Uncover frustrations, understand bugs and fix slowdowns like never before with <strong><a href="https://github.com/openreplay/openreplay" target="_blank">OpenReplay</a></strong> — an open-source session replay suite for developers. It can be <strong>self-hosted</strong> in minutes, giving you complete control over your customer data.</em></p>
<img alt="OpenReplay" style="margin-top:5px; margin-bottom:5px;" width="768" height="400" src="https://raw.githubusercontent.com/openreplay/openreplay/main/static/openreplay-git-hero.svg" class="astro-UXNKDZ4E" loading="lazy" decoding="async">
<p><em>Happy debugging! <a href="https://openreplay.com" target="_blank">Try using OpenReplay today.</a></em><p>
<hr/>
</div>





## Deploying to Netlify

Netlify build requires a build command to run your code. This usually would be found in a `package.json` file. However, Deno does not use `npm` or a `package.json` file to manage dependencies; hence you need to specify the build command in a `netlify.toml` file at the root of our project.

**Step 6:** In your root directory, create a `netlify.toml` file and enter the code below:

```
[build]
command = "deno run --allow-net deno.ts"
publish = "."
```
This file specifies the build command (`deno run --allow-net deno.ts`) and the publish directory for the app. The `".``` tells Netlify to publish in the current directory. 
**NB:** You can change the `deno.ts` to any name you've named your file.

The next step is to create a GitHub repository and push the Deno app to the GitHub repo as shown in the image below; you can check out [my sample repo](https://github.com/PE-Ibeabcuhi/Deno_practice):

![-](https://blog.openreplay.com/images/step-by-step--deploying-a-deno-app-to-netlify/images/s_F6DE0ACEA327969C481DF72792C10DDA9ED799626722E4E0B23E741F6EA78AEC_1675846408734_Screenshot+2023-02-08+at+9.52.30+AM.png)


**PS:** This project is a sample Deno web app and is just for the sole purpose of this tutorial, so it doesn't contain any real information.

Now that you have the project in GitHub, connect your Netlify account with your GitHub account. If you don't have a Netlify account, you can [create a free one](https://app.netlify.com/signup). Log into Netlify with your GitHub account and follow the prompts to authorize Netlify Auth. 
Once this is done, you are redirected to our GitHub teams page. You need to create a new site from Git, as shown below:

![-](https://blog.openreplay.com/images/step-by-step--deploying-a-deno-app-to-netlify/images/s_F6DE0ACEA327969C481DF72792C10DDA9ED799626722E4E0B23E741F6EA78AEC_1675846970810_Screenshot+2023-02-08+at+10.00.19+AM.png)


Click on the `Add new site` drop-down and select the `Import an existing project` option from the drop-down. You'll be redirected to the page below:

![-](https://blog.openreplay.com/images/step-by-step--deploying-a-deno-app-to-netlify/images/s_F6DE0ACEA327969C481DF72792C10DDA9ED799626722E4E0B23E741F6EA78AEC_1675847330448_Screenshot+2023-02-08+at+10.07.28+AM.png)


Select the GitHub option, follow the prompts, and select your Deno repository on GitHub. After selecting the repository where the Deno application is hosted, you'll be redirected to set the basic build setting:

![-](https://blog.openreplay.com/images/step-by-step--deploying-a-deno-app-to-netlify/images/s_F6DE0ACEA327969C481DF72792C10DDA9ED799626722E4E0B23E741F6EA78AEC_1675849303657_Screenshot+2023-02-08+at+10.30.29+AM.png)


The base directory specifies where we want the Netlify build system to check for dependency management files: in our case, `deno.ts`. The build command specifies the command required to build the site: `deno run --allow-net deno.ts`. The publish directory (relative to the root of your repo) contains the deploy-ready files and assets generated by the build. You can read more on the [documentation](https://docs.netlify.com/configure-builds/overview/?_ga=2.222331292.628843526.1675776310-1408860276.1673866091#basic-build-settings]) to understand the build settings.

Once this is set, click on the `Deploy site` option, and that's it; you have successfully deployed to Netlify. You can preview your site from the test domain created by Netlify:

![-](https://blog.openreplay.com/images/step-by-step--deploying-a-deno-app-to-netlify/images/s_F6DE0ACEA327969C481DF72792C10DDA9ED799626722E4E0B23E741F6EA78AEC_1675850850708_Screenshot+2023-02-08+at+11.06.38+AM.png)


To customize your domain name, click on `site settings` (the first option from the right in the menu above); under site information, you can change the site name.


## Conclusion

In this tutorial, you learned how to deploy a simple Deno app to Netlify, a great platform for hosting web applications. With Netlify, you can easily host your Deno apps, freeing you up to focus on writing great code. And with its seamless integration with GitHub, deploying to Netlify is a quick and straightforward process.