Skip to content

Instantly share code, notes, and snippets.

@thgaskell

thgaskell/main.ts

Created Mar 27, 2020
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@thgaskell thgaskell commented Mar 27, 2020

Just trying out executing deno script from a URL

Usage (--name John flag is included)

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

This comment has been minimized.

Copy link
Owner Author

@thgaskell thgaskell commented Mar 27, 2020

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

This comment has been minimized.

Copy link
Owner Author

@thgaskell thgaskell commented Mar 27, 2020

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