Skip to content

Instantly share code, notes, and snippets.

@thgaskell
Created March 27, 2020 00:18
Show Gist options
  • Save thgaskell/20d209a5da49be7a01933ec86d7ae908 to your computer and use it in GitHub Desktop.
Save thgaskell/20d209a5da49be7a01933ec86d7ae908 to your computer and use it in GitHub Desktop.
Hello, Deno!
import { parse } from "https://deno.land/std/flags/mod.ts";
function greet(name?: string): void {
if (!name) {
console.log('Hello, World!');
} else {
console.log(`Hello, ${name}!`);
}
}
const { name } = parse(Deno.args);
greet(name);
@thgaskell
Copy link
Author

If you just want to use the latest version of the script, you can omit the commit hash (before the file name).

Usage

$ deno run https://gist.githubusercontent.com/thgaskell/20d209a5da49be7a01933ec86d7ae908/raw/main.ts --name Deno
Hello, Deno!

@thgaskell
Copy link
Author

You can use the deno install command to save the file as an executable:

$ deno install hello-deno https://gist.githubusercontent.com/thgaskell/20d209a5da49be7a01933ec86d7ae908/raw/main.ts
Download https://gist.githubusercontent.com/thgaskell/20d209a5da49be7a01933ec86d7ae908/raw/main.ts
Compile https://gist.githubusercontent.com/thgaskell/20d209a5da49be7a01933ec86d7ae908/raw/main.ts
Download https://deno.land/std/flags/mod.ts
Download https://deno.land/std/testing/asserts.ts
Download https://deno.land/std/fmt/colors.ts
Download https://deno.land/std/testing/diff.ts
Download https://deno.land/std/testing/format.ts
✅ Successfully installed hello-deno

After that, you may be prompted to add the deno binary path to your $PATH variable. Once your shell script resolves the deno binary path, you should be able to run the command with your chosen executable name:

$ hello-deno
Hello, World!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment