Skip to content

Instantly share code, notes, and snippets.

@FoxNeo
Last active June 13, 2022 15:26
Show Gist options
  • Save FoxNeo/f7a7420a756d2e61563296eafad441e6 to your computer and use it in GitHub Desktop.
Save FoxNeo/f7a7420a756d2e61563296eafad441e6 to your computer and use it in GitHub Desktop.
A short tutorial, how to run TypeScript in Terminal

Run TypeScript code from terminal

Create a node project:

$ npm init

Add to your node project:

$ npm install typescript --save-dev

Add TypeScript config

$ npx tsc --init

Create a ts file for example narahate.ts:

function buildNarahate(firstName: string, layer?: string) {
  if (layer) {
    return firstName + " lives in the" + layer + " layer of the Abyss";
  } else {
    return firstName;
  }
}
console.log(buildNarahate("Belaf", "sixth"));
console.log(buildNarahate("Belaf"));

then run:

$ npx ts-node ./typescriptfilename.ts

Output:

  • Belaf lives in the sixth layer of the Abyss
  • Belaf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment