Run TypeScript file globally 🌠 with ts-node

Β·

1 min read

Run Globally mean we can run ts-node command everywhere without package.json.

Globally install ts-node

pnpm install -g typescript ts-node tslib @types/node

# verify
ts-node -v
  • tslib is a runtime library for TypeScript that contains all of the TypeScript helper functions.
  • @types/node contains type definitions for Node.js.

Prepare a simple sample

Create a ts file:

touch test.ts

Write a simple sample:

const teamName: string = 'πŸ¦†πŸ¦†πŸ¦†';

console.log('🌊', teamName);

Run ts file everywhere

ts-node test.ts

Expected output is "🌊 πŸ¦†πŸ¦†πŸ¦†".