JavaScript and TypeScript Tips

Running JavaScript and TypeScript Files in VS Code the Easy Way

Tod Gentille
1 min readJul 27, 2021

Sometimes you want to quickly prove a small bit of code works. There are multiple ways to do this, but this is the easiest one I’ve found.

animated person celebrating at laptop

I have .git configured so that any file that starts with a period doesn’t get uploaded into source control. Therefore I start by creating a file named either .run.js or .run.ts. I keep these files at the root of my project and reuse them whenever I want to experiment with code.

Now I can write any kind code I want in there. When it’s a JavaScript file I just drop into the integrated terminal and type, node .run, and the terminal gets any results. For Typescript I type, ts-node .run and the TypeScript file gets compiled and executed.

I have also used VS Code tasks, and the debugger to run code, but this approach strikes me as the most straight-forward.

Thanks for reading, I have written more (usually longer) JavaScript and TypeScript tip articles.

Code in peace.

--

--

Tod Gentille

Pluralsight author & software developer since 1980. Mostly tech articles. Love fountain pens. Opinions expressed here are my own. https://gentille.us/subscribe