Step #1: Set the Deno installation directory
Step #2: Run Deno’s official installation script
Step #3: Verify Deno installation
Installing Deno was super easy. At this point, running a Deno script that serves content would only be able to serve the data to localhost. We will use the web server nginx to make the content publicly available.
Step #4: Install nginx
|RHEL / CentOS / Amazon Linux||sudo yum install nginx|
|Ubuntu / Debian||sudo apt-get install nginx|
|Fedora||sudo dnf -y install nginx|
Step #5: Configure nginx to forward Deno output
For this step, you will need to edit /etc/nginx/nginx.conf to setup forwarding on port 8000. To do so, add the following code in the location block of the config file:
proxy_pass http://localhost:8000; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_cache_bypass $http_upgrade;
Step #6: Start nginx
|RHEL / CentOS / Amazon Linux||sudo systemctl start nginx|
|Ubuntu / Debian||sudo systemctl start nginx|
|Fedora||sudo systemctl start nginx|
At this point, loading your server/host endpoint will return an nginx error. nginx is expecting to forward the request to port 8000, but there is currently no process listening on port 8000
Step #7: Start Deno server
In this example, we will run a very simple file server. The script will serve files from the current directory. Nginx is configured to forward connections to port 8000, so we need to explicitly tell the script to run on port 8000.
Your Deno server is now publicly available!
This executes from my local workspace, which contains a file test-file.txt.
Note: Deno is secure by default, meaning the environment is sandboxed. The command to run the example script requires the –allow-net and –allow-read argument flags to server the content via the network