Running and Installing Scripts
Explore how to run local and remote Deno scripts, understand Deno's approach to script execution similar to a browser, and learn to install utility programs system-wide with proper permissions. Gain practical experience with echo servers and file server modules to run and install scripts efficiently in Deno.
We'll cover the following...
Run a local and remote web server
In one of his first talks, and in Deno’s first version release notes Dahl used the following sentence: “Deno is like a web browser for command-line scripts.”
This sentence makes more and more sense once we start using Deno. Let’s explore it a little further.
When we access a URL, a browser runs the code there. It interprets the HTML and the CSS and then executes some JavaScript. Deno, by following its premise of being a browser for scripts, needs a URL to run code. Let’s see it in action.
Honestly, it isn’t very different from what we’ve already done a couple of times already. As a refresher, the last time we executed our simple web server, we did the following:
deno run --allow-net --import-map=import-maps.json --unstable hello-http-server.js
Here, hello-http-server.js is just a file in the current folder.
Let’s try to do the same with a remote file—a file that is served through HTTP.
Echo server
We’ll execute an echo server from the Deno standard library’s set of examples.
The source code can be found here. It’s a server that echoes back whatever is sent to it:
deno run --allow-net https://deno.land/std@0.83.0/examples/echo_server.ts