JavaScript and TypeScript Tips
Running JavaScript and TypeScript Files in VS Code the Easy Way
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.
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.