Last Updated On By Khizer Ali
Ryan Dahl has launched Deno version 1.0 on 13 May 2020 after his announcement in JSConf EU Conference in 2018. Deno has several new features, and these features also include its subcommands.
There are some subcommands available in Deno which you can use to perform different operations in your application. You can also see the list of those commands by running deno help or deno –help in your command prompt. Below are the subcommands which are available in Deno.
bundle | : Bundle module and dependencies into a single file |
cache | : Cache the dependencies |
completions | : Generate shell completions |
doc | : Show documentation for a module |
eval | : Eval script |
fmt | : Format source files |
help | : Prints this message or the help of the given subcommand(s) |
info | : Show info about cache or info related to source file |
install | : Install script as an executable |
repl | : Read Eval Print Loop |
run | : Run a program given a filename or url to the module |
test | : Run tests |
types | : Print runtime TypeScript declarations |
upgrade | : Upgrade deno executable to newest version |
You can see the brief information or detail information of any subcommand by running Deno <subcommand> -h or deno <subcommand> –help respectively. But you don’t need to worry. In this article, you are going to study each subcommand in detail and with a practical example.
Table of Contents
This command output a single JavaScript file which includes all the dependencies of the given input.
If you exclude the output file then, the bundle will be sent to standard output.
Now you can run the bundle like any other module like this:
deno run colors.bundle.js
Syntax:
deno bundle [OPTIONS] [out_file]
Options:
--cert | Load certificate authority from PEM encoded file | |
-c, | --config | Load tsconfig.json configuration file |
-h, | --help | Prints help information |
--importmap | UNSTABLE: Load import map file | |
-L, | --log-level | Set log level [possible values: debug, info] |
-q, | –quiet | Suppress diagnostic output |
–unstable | Enable unstable APIs |
For any module, cache and compile remote dependencies recursively.
Download and compile a module with all of its static dependencies and save them in the local cache, without running any code:
Future run of this module will not download this module because it has been added to your cache, but if you want to then you have to use –reload.
Syntax:
deno cache [OPTIONS] <files>…
Options:
–cert | Load certificate authority from PEM encoded file | |
-c | –config | Load tsconfig.json configuration file |
-h | –help | Prints help information |
–importmap | UNSTABLE: Load import map file | |
–lock | Check the specified lock file | |
–lock-write | Write lock file. Use with –lock. | |
-L | –log-level | Set log level [possible values: debug, info] |
–no-remote | Do not resolve remote modules | |
-q | –quiet | Suppress diagnostic output |
-r | –reload= | Reload source code cache (recompile TypeScript) |
–unstable | Enable unstable APIs |
We can get shell completions for the Deno by outputting a profile script for the shell of our choice.
Use this command to put the completions in your bash profile:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.
deno completions bash > /usr/local/etc/bash_completion.d/deno.bash
Syntax:
deno completions [OPTIONS] <shell>
Options:
-h | –help | Prints help information |
-L | –log-level <log-level> | Set log level [possible values: debug, info] |
-q | –quiet | Suppress diagnostic output |
Possible values for shell are: zsh, bash, fish, powershell, elvish
The deno doc command can use locally to show documentation for a module
Output documentation to standard output:
deno doc ./path/to/module.ts
Output documentation in JSON format:
deno doc –json ./path/to/module.ts
Target a specific symbol:
deno doc ./path/to/module.ts MyClass.someField
Show documentation for runtime built-ins:
deno doc
deno doc –builtin Deno.Listener
Syntax:
deno doc [OPTIONS] [ARGS]
Options:
-h, | --help | Prints help information |
--json | Output documentation in JSON format. | |
-L, | --log-level <log-level> | Set log level [possible values: debug, info] |
-q, | –quiet | Suppress diagnostic output |
-r, | –reload=<CACHE_BLACKLIST> | Reload source code cache (recompile TypeScript) |
| –unstable | Enable unstable APIs |
The deno eval command is used to evaluate the JavaScript or TypeScript code directly from the command line.
deno eval “console.log(‘Hello’)”
To evaluate the TypeScript code:
deno eval –ts “const v: string = ‘hello’; console.log(v)”
Note: This command has implicit access to all permission.
Syntax:
deno eval [OPTIONS] <code>
Options:
| –cert <FILE> | Load certificate authority from PEM encoded file |
-h | –help | Prints help information |
| –inspect=<HOST:PORT> | activate inspector on host:port (default: 127.0.0.1:9229) |
| –inspect brk=<HOST:PORT> | activate inspector on host:port and break at the start of the user script |
-L | –log-level <log-level> | Set log level [possible values: debug, info] |
-q | –quiet | Suppress diagnostic output |
-T | –ts | Treat eval input as TypeScript |
| –unstable | Enable unstable APIs |
| –v8-flags=<v8-flags> | Set V8 command-line options. For help: –v8-flags=–help |
Formatting your code in one of the problems which you usually face when you are working professionally. There are different formatting that people follow. So, to choose the format style could be difficult for you. But, Deno has a built-in formatter that automatically formats JavaScript and TypeScript code, so you don’t need to worry about it anymore.
deno fmt | Format all the files present in the current directory. |
deno fmt file1.ts file2.ts | Formats the specified mention files |
deno fmt –check | To check whether a file is formatted or not. (If formatted nothing appear) (If not formatted that it will mention the number of files which need to be format) |
cat file.ts | deno fmt – | Format stdin and write to stdout |
Ignore formatting a piece of code by preceding it with an ignore comment.
// deno-fmt-ignore
Ignore formatting a file by adding an ignore comment at the top of the file.
// deno-fmt-ignore-file
Syntax:
deno fmt [OPTIONS] [FILES]…
Options:
| –check | Check if the source files are formatted. |
-h | –help | Prints help information |
-L | –log-level <log-level> | Set log level [possible values: debug, info] |
-q | –quiet | Suppress diagnostic output |
Deno help commands display usage and explanation of all commands or a given specific commands.
Output all deno commands and environment variables.
deno help
Output explanation for the fmt command
deno help fmt
Output explanation for the help command
deno help help
The info command provides information about the given module or the cache directories.
deno info https://deno.land/std/http/server.ts
The following information is shown:
local: Local path of the file.
type: JavaScript, TypeScript, or JSON.
compiled: Local path of compiled source code. (TypeScript only.)
map: Local path of source map. (TypeScript only.)
deps: Dependency tree of the source file.
> deno info https://deno.land/std/http/server.ts
Download https://deno.land/std/http/server.ts
....
Compile https://deno.land/std/http/server.ts
local: C:\Users\AppData\Local\deno\deps\https\deno.land\c1723c570639ab9ac7b57b4c6169663cda9d5f85151d647088ae17884514b868
type: TypeScript
compiled: C:\Users\AppData\Local\deno\gen\https\deno.land\std\http\server.ts.js
map: C:\Users\AppData\Local\deno\gen\https\deno.land\std\http\server.ts.js.map
deps:
https://deno.land/std/http/server.ts
├── https://deno.land/std/encoding/utf8.ts
├─┬ https://deno.land/std/io/bufio.ts
│ ├─┬ https://deno.land/std/io/util.ts
│ │ ├─┬ https://deno.land/std/path/mod.ts
│ │ │ ├─┬ https://deno.land/std/path/win32.ts
│ │ │ │ ├── https://deno.land/std/path/_constants.ts
│ │ │ │ ├─┬ https://deno.land/std/path/_util.ts
│ │ │ │ │ └── https://deno.land/std/path/_constants.ts
│ │ │ │ └─┬ https://deno.land/std/testing/asserts.ts
│ │ │ │ ├── https://deno.land/std/fmt/colors.ts
│ │ │ │ └── https://deno.land/std/testing/diff.ts
│ │ │ ├─┬ https://deno.land/std/path/posix.ts
│ │ │ │ ├── https://deno.land/std/path/_constants.ts
│ │ │ │ └── https://deno.land/std/path/_util.ts
│ │ │ ├─┬ https://deno.land/std/path/common.ts
│ │ │ │ └── https://deno.land/std/path/separator.ts
│ │ │ ├── https://deno.land/std/path/separator.ts
│ │ │ ├── https://deno.land/std/path/interface.ts
│ │ │ └─┬ https://deno.land/std/path/glob.ts
│ │ │ ├── https://deno.land/std/path/separator.ts
│ │ │ ├── https://deno.land/std/path/_globrex.ts
│ │ │ ├── https://deno.land/std/path/mod.ts
│ │ │ └── https://deno.land/std/testing/asserts.ts
│ │ └── https://deno.land/std/encoding/utf8.ts
│ └── https://deno.land/std/testing/asserts.ts
├── https://deno.land/std/testing/asserts.ts
├─┬ https://deno.land/std/async/mod.ts
│ ├── https://deno.land/std/async/deferred.ts
│ ├── https://deno.land/std/async/delay.ts
│ └─┬ https://deno.land/std/async/mux_async_iterator.ts
│ └── https://deno.land/std/async/deferred.ts
└─┬ https://deno.land/std/http/_io.ts
├── https://deno.land/std/io/bufio.ts
├─┬ https://deno.land/std/textproto/mod.ts
│ ├── https://deno.land/std/io/util.ts
│ ├─┬ https://deno.land/std/bytes/mod.ts
│ │ └── https://deno.land/std/io/util.ts
│ └── https://deno.land/std/encoding/utf8.ts
├── https://deno.land/std/testing/asserts.ts
├── https://deno.land/std/encoding/utf8.ts
├── https://deno.land/std/http/server.ts
└── https://deno.land/std/http/http_status.ts
Without any additional document, on running deno info, we get the following output:
DENO_DIR: Directory containing Deno-managed files.
Remote modules cache: Subdirectory containing downloaded remote modules.
TypeScript compiler cache: Subdirectory containing TS compiler output.
DENO_DIR location: "C:\\Users\\ AppData\\Local\\deno"
Remote modules cache: "C:\\Users\\ AppData\\Local\\deno\\deps"
TypeScript compiler cache: "C:\\Users\\ AppData\\Local\\deno\\gen"
Syntax:
deno info [OPTIONS] [file]
options:
| –cert <FILE> | Load certificate authority from PEM encoded file |
-h, | –help | Prints help information |
-L, | –log-level <log-level> | Set log level [possible values: debug, info] |
-q, | –quiet | Suppress diagnostic output |
| –unstable | Enable unstable APIs |
with deno install, you can install a script as an executable in the installation root’s bin directory.
deno install –allow-net –allow-read https://deno.land/std/http/file_server.ts
deno install https://deno.land/std/examples/colors.ts
To change the executable name, use -n/–name:
To change the installation root, use –root:
deno install –allow-net –allow-read –root /usr/local https://deno.land/std/http/file_server.ts
Syntax:
deno install [OPTIONS] <code>…
options:
-A | –allow-all | Allow all permissions |
| –allow-env | Allow environment access |
| –allow-hrtime | Allow high-resolution time measurement |
| –allow-net=<allow-net> | Allow network access |
| –allow-plugin | Allow loading plugins |
| –allow-read=<allow-read> | Allow file system read access |
| –allow-run | Allow running subprocesses |
| –allow-write=<allow-write> | Allow file system write access |
| –cert <FILE> | Load certificate authority from PEM encoded file |
-f | –force | Forcefully overwrite existing installation |
-h | –help | Prints help information |
-L | –log-level <log-level> | Set log level [possible values: debug, info] |
-n | –name <name> | Executable file name |
-q | –quiet | Suppress diagnostic output |
| –root <root> | Installation root |
| –unstable | Enable unstable APIs |
Repl stands for “Read Eval Print Loop”. It is a quick and easy way to test simple deno/JavaScript code. Running deno repl is the same as running deno in command prompt.
syntax:
deno repl [OPTIONS]
options:
| –cert <FILE> | Load certificate authority from PEM encoded file |
-h, | –help | Prints help information |
| –inspect=<HOST:PORT> | activate inspector on host:port (default: 127.0.0.1:9229) |
| –inspect-brk=<HOST:PORT> | activate inspector on host: port and break at the start of the user script |
-L, | –log-level <log-level> | Set log level [possible values: debug, info] |
-q, | –quiet | Suppress diagnostic output |
| –unstable | Enable unstable APIs |
| –v8-flags=<v8-flags> | Set V8 command-line options. For help: –v8-flags=–help |
You can use deno run <source> to initiate a deno app.
The source can be a .ts file, .js file, or even a URL. For example:
deno run https://deno.land/std/examples/welcome.ts
Download https://deno.land/std/examples/welcome.ts
Compile https://deno.land/std/examples/welcome.ts
Welcome to Deno 🦕
If you run this URL again, it gets compiled directly because it has now cached by deno and doesn’t need to download again.
deno run https://deno.land/std/examples/welcome.ts
Compile https://deno.land/std/examples/welcome.ts
Welcome to Deno 🦕
Syntax:
deno run [OPTIONS] <SCRIPT_ARGS>
Options:
-A | –allow-all | Allow all permissions |
| –allow-env | Allow environment access |
| –allow-hrtime | Allow high-resolution time measurement |
| –allow-net=<allow-net> | Allow network access |
| –allow-plugin | Allow loading plugins |
| –allow-read=<allow-read> | Allow file system read access |
| –allow-run | Allow running subprocesses |
| –allow-write=<allow-write> | Allow file system write access |
| –cached-only | Require that remote dependencies are already cached |
| –cert <FILE> | Load certificate authority from PEM encoded file |
-c | –config <FILE> | Load tsconfig.json configuration file |
-h | –help | Prints help information |
| –importmap <FILE> | UNSTABLE: Load import map file |
| –inspect=<HOST:PORT> | activate inspector on host:port (default: 127.0.0.1:9229) |
| –inspect-brk=<HOST:PORT> | activate inspector on host: port and break at the start of the user script |
| –lock <FILE> | Check the specified lock file |
| –lock-write | Write lock file. Use with –lock. |
-L | –log-level <log-level> | Set log level [possible values: debug, info] |
| –no-remote | Do not resolve remote modules |
-q | –quiet | Suppress diagnostic output |
-r | –reload=<CACHE_BLACKLIST> | Reload source code cache (recompile TypeScript) |
| –seed <NUMBER> | Seed Math.random() |
| –unstable | Enable unstable APIs |
| –v8-flags=<v8-flags> | Set V8 command-line options. For help: –v8-flags=–help |
This command runs tests using Deno’s built-in test runner.
Evaluate the given modules, run all tests declared with ‘Deno.test()’ and report results to standard output:
deno test src/fetch_test.ts src/signal_test.ts
Syntax:
deno test [OPTIONS] [files]…
Options:
-A | –allow-all | Allow all permissions |
| –allow-env | Allow environment access |
| –allow-hrtime | Allow high-resolution time measurement |
| –allow-net=<allow-net> | Allow network access |
| –allow-plugin | Allow loading plugins |
| –allow-read=<allow-read> | Allow file system read access |
| –allow-run | Allow running subprocesses |
| –allow-write=<allow-write> | Allow file system write access |
| –allow-none | Don’t return error code if no test files are found |
| –cached-only | Require that remote dependencies are already cached |
| –cert <FILE> | Load certificate authority from PEM encoded file |
-c | –config <FILE> | Load tsconfig.json configuration file |
| –failfast | Stop on first error |
| –filter <filter> | A pattern to filter the tests to run by |
-h | –help | Prints help information |
| –importmap <FILE> | UNSTABLE: Load import map file |
| –inspect=<HOST:PORT> | activate inspector on host:port (default: 127.0.0.1:9229) |
| –inspect-brk=<HOST:PORT> | activate inspector on host: port and break at the start of the user script |
| –lock <FILE> | Check the specified lock file |
| –lock-write | Write lock file. Use with –lock. |
-L | –log-level <log-level> | Set log level [possible values: debug, info] |
| –no-remote | Do not resolve remote modules |
-q | –quiet | Suppress diagnostic output |
-r | –reload=<CACHE_BLACKLIST> | Reload source code cache (recompile TypeScript) |
| –seed <NUMBER> | Seed Math.random() |
| –unstable | Enable unstable APIs |
| –v8-flags=<v8-flags> | Set V8 command line options. For help: –v8-flags=–help |
the deno type command print the runtime Typescript declaration.
This command writes the current deno type declaration to the lib.deno.d.ts file.
deno types > lib.deno.d.ts
Syntax:
deno types [OPTIONS]
Options:
-h, | –help | Prints help information |
-L, | –log-level <log-level> | Set log level [possible values: debug, info] |
-q, | –quiet | Suppress diagnostic output |
| –unstable | Enable unstable APIs |
This command is used to update the executable to the latest version, default to the latest.
deno upgrade
Syntax:
deno upgrade [OPTIONS]
Options:
| –dry-run | Perform all checks without replacing old exe |
-f, | –force | Replace current exe even if not out-of-date |
-h, | –help | Prints help information |
-L, | –log-level <log-level> | Set log level [possible values: debug, info] |
-q, | –quiet | Suppress diagnostic output |
| –version <version> | The version to upgrade to |
In this article, we’ve studied all the subcommands available in Deno with its description and example. I hope it’ll be beneficial for you to understand these core commands of Deno.