2019-07-11 05:58:18 -04:00
|
|
|
# Deno example programs
|
2018-12-19 13:50:48 -05:00
|
|
|
|
2019-08-05 18:00:28 -04:00
|
|
|
This module contains small scripts that demonstrate use of Deno and its standard
|
|
|
|
module.
|
2018-12-19 13:50:48 -05:00
|
|
|
|
2019-08-05 18:00:28 -04:00
|
|
|
You can run these examples using just their URL or install the example as an
|
|
|
|
executable script which references the URL. (Think of installing as creating a
|
|
|
|
bookmark to a program.)
|
2018-12-24 10:28:01 -05:00
|
|
|
|
2019-08-05 18:00:28 -04:00
|
|
|
### A TCP echo server
|
2018-12-19 13:50:48 -05:00
|
|
|
|
2019-08-05 18:00:28 -04:00
|
|
|
```shell
|
2020-02-22 18:51:04 -05:00
|
|
|
deno --allow-net https://deno.land/std/examples/echo_server.ts
|
2019-08-05 18:00:28 -04:00
|
|
|
```
|
2018-12-19 13:50:48 -05:00
|
|
|
|
2019-08-05 18:00:28 -04:00
|
|
|
Or
|
2018-12-24 10:28:01 -05:00
|
|
|
|
2019-08-05 18:00:28 -04:00
|
|
|
```shell
|
2020-05-01 15:33:11 -04:00
|
|
|
deno install --allow-net https://deno.land/std/examples/echo_server.ts
|
2018-12-19 13:50:48 -05:00
|
|
|
```
|
2019-08-05 18:00:28 -04:00
|
|
|
|
|
|
|
### cat - print file to standard output
|
|
|
|
|
|
|
|
```shell
|
2020-05-01 15:33:11 -04:00
|
|
|
deno install --allow-read -n deno_cat https://deno.land/std/examples/cat.ts
|
2019-07-11 05:58:18 -04:00
|
|
|
deno_cat file.txt
|
|
|
|
```
|
|
|
|
|
2019-08-05 18:00:28 -04:00
|
|
|
### catj - print flattened JSON to standard output
|
2019-07-11 05:58:18 -04:00
|
|
|
|
2019-08-05 18:00:28 -04:00
|
|
|
A very useful command by Soheil Rashidi ported to Deno.
|
|
|
|
|
|
|
|
```shell
|
2020-05-01 15:33:11 -04:00
|
|
|
deno install --allow-read https://deno.land/std/examples/catj.ts
|
2019-07-11 05:58:18 -04:00
|
|
|
catj example.json
|
|
|
|
catj file1.json file2.json
|
|
|
|
echo example.json | catj -
|
|
|
|
```
|
|
|
|
|
2019-10-21 10:36:01 -04:00
|
|
|
### curl - print the contents of a url to standard output
|
|
|
|
|
|
|
|
```shell
|
2020-02-22 18:45:35 -05:00
|
|
|
deno --allow-net=deno.land https://deno.land/std/examples/curl.ts https://deno.land/
|
2019-10-21 10:36:01 -04:00
|
|
|
```
|
|
|
|
|
2019-08-05 18:00:28 -04:00
|
|
|
### gist - easily create and upload Gists
|
2019-07-11 05:58:18 -04:00
|
|
|
|
|
|
|
```
|
2018-12-19 13:50:48 -05:00
|
|
|
export GIST_TOKEN=ABC # Generate at https://github.com/settings/tokens
|
2020-05-01 15:33:11 -04:00
|
|
|
deno install --allow-net --allow-env https://deno.land/std/examples/gist.ts
|
2019-07-11 05:58:18 -04:00
|
|
|
gist --title "Example gist 1" script.ts
|
|
|
|
gist --t "Example gist 2" script2.ts
|
2018-12-19 13:50:48 -05:00
|
|
|
```
|
2020-02-22 18:51:04 -05:00
|
|
|
|
|
|
|
### chat - WebSocket chat server and browser client
|
|
|
|
|
|
|
|
```shell
|
|
|
|
deno --allow-net --allow-read https://deno.land/std/examples/chat/server.ts
|
|
|
|
```
|
|
|
|
|
|
|
|
Open http://localhost:8080 on the browser.
|