The JS runtimes
Published in

The JS runtimes

Deno on Windows: Hello world HTTP server

In the previous article, we covered how to install Deno on Windows using PowerShell IWR and IEX commands.

In this article, we’ll continue exploring Deno on Windows by writing simple ‘Hello world’ HTTP servers that work over HTTP and HTTPS.

Let’s get started.

Hello world server

The code of the basic hello world server is exactly the same as what would have been used on other platforms like Mac or Linux. We can import the serve API from standard library’s http module.

Here is a screenshot of the code:

We’ll run the hello world server in a short while.

First, let’s do a quick test of Deno’s formatter:

The suggestions are simply about spaces around braces. Let’s accept them.

Next, let’s use the cache command to download and compile all the dependencies:

On Windows, Deno installs in the following directory: C:\Users\14089\AppData\Local\deno. The usual deps and gen directories are there.

Finally, we can run the application with allowed permissions:

  • Local socket permission for port 8080

We can test it out using curl command:

The hello world application works fine! There is no difference in the application code.

Let’s move on to write the same application over HTTPS.

Hello world over HTTPS

The ‘hello world’ server over HTTPS is almost the same as it’s Mac or Linux counterparts. The only difference would be the way paths to the certificate and key file are specified. Just to show the difference, we’ll use absolute paths on Windows.

Here is the code of the server that uses the same serveTls API:

Note that we needed to use double backslash in paths.

We’ll skip the formatting and caching part, as the usage and results would be almost the same.

The application can be started with required permissions:

  • Local socket permission for port 8080
  • Read permission to the directory containing the certs

We can test it out using curl command:

In the next article, we’ll see how OS/process specific APIs provided by Deno works on Windows.

This story is a part of the exclusive medium publication on Deno: Deno World.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store