deno_install
scripts. You can do this on Linux or macOS with:curl -fsSL https://deno.land/x/install/install.sh | sh
choco install deno
.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());
deno run date_time.js
// first_argument.js
console.log(Deno.args[0]);
the stdin
by using "-"
(without quotes).deno run date_time.js
deno run https://example.com/date_time.js
echo "console.log('Hello Deno')" | deno run
// args.js
console.log(Deno.args, Deno.args.length);
fetch()
, Web Worker and WebAssembly
.deno run --allow-net server.js
--allow-net
provides network access permission to our program, otherwise Deno will throw a PermissionDenied
error. This example:deno_server
index.html
, and paste the following code into it:server.js
and paste the following code into it:deno run --allow_net --allow_read server.js
--allow-net and --allow-read
are required for the code to run successfully.DENO_DIR
, or the default system's cache directory if DENO_DIR is not specified.sample.ts
, and paste the following code:--allow-read
flag to see how Deno behaves by default:deno run sample.ts
deno run --allow-read sample.ts
Deno.writeFile()
method provides asynchronous methods for file writing. Let's explore with an example: --allow-write
flag.sample1.txt
file to confirm the write, the Deno namespace also provides readTextFile
which can be easily used to read text files:deno fmt
command.deno fmt
deno fmt sample.txt sample1.txt
cat sample.ts | deno fmt -
deno fmt --check
deno fmt --check sample.js sample.ts