Hostwinds Tutorials
Search results for:
Table of Contents
Deno allows you to run Javascript in a fast, secure environment. Deno is web-oriented and built for modern JS. Similar to Node.js, Deno allows for seamless backend integration with front-end Javascript code. By default, Deno's server is only locally available. To publicly expose the server interface, Nginx can be used as a proxy. To run this, you will need a Red Hat or Debian-based Linux VPS.
export DENO_INSTALL='/usr'
sudo curl -fsSL https://deno.land/x/install/install.sh | sh
which deno
/usr/bin/deno
Installing Deno was super easy. At this point, running a Deno script that serves content would only serve the data to localhost. We will use the webserver Nginx to make the content publicly available.
sudo yum install Nginx
sudo apt-get install Nginx Fedora sudo dnf -y install Nginx.
For this step, you will need to edit /etc/nginx/nginx.conf to set up forwarding on port 8000. To do so, add the following code in the location block of the config file:
vi /etc/nginx/nginx.conf
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;
sudo systemctl start nginx
sudo systemctl start nginx
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
In this example, we will run a straightforward file server. The script will serve files from the current directory. Nginx is configured to forward connections to port 8000, so we need to tell the script to run on port 8000 explicitly.
deno run --allow-read --allow-net https://deno.land/std/http/file_server.ts --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 serve the content via the network.
Written by Hostwinds Team / June 16, 2020