Deno is a simple, modern, and secure runtime for JavaScript and TypeScript applications built with the Chromium V8 JavaScript engine and Rust, created to avoid several pain points and regrets with Node.js.
Deno was originally announced in 2018 and reached 1.0 in 2020, created by the original Node.js founder Ryan Dahl and other mindful contributors.
The easiest way to install Deno is to use the deno_install
scripts. You can do this on Linux or macOS with:
curl -fsSL https://deno.land/x/install/install.sh | sh
Windows users can leverage Chocolatey:
choco install deno
A successful install with Linux looks like this:
Note: You may also need to export the deno directories to make the deno command globally available.
There are additional ways to install Deno.
Simple Example
Deno uses .js
and .ts
file extensions (though it will run any JavaScript or TypeScript file regardless of extension). Our first example demonstrates how we can safely write a browser-based Deno application, a simple JavaScript program that prints the current date and time.
// date_time.js
console.log(new Date());
Let’s run the code:
deno run date_time.js
Results:
2020-07-10T02:20:31.298Z
With Deno, we can log command-line arguments with just one line of code:
// first_argument.js
console.log(Deno.args[0]);
The run command runs any Deno code. And if you’re stuck, run deno --help, or deno -h, to get help using denocommands.
Deno also provides a way to run programs from a local file, a URL, or by integrating with other applications in the stdin
by using "-"
(without quotes).
Running code from filename:
deno run date_time.js
Running code from a URL is nearly identical:
deno run https://example.com/date_time.js
Read code from stdin:
echo "console.log('Hello Deno')" | deno run
#deno #javascript #typescript #web development #rust #architecture & design #development #article