Typescript scripts in the command line: Deno 2.0 vs Node.JS

Whether you are new to the development world or a seasoned developer, scripts make life easier. They automate repetitive tasks, streamline complex processes, and produce predictable output, phasing out the human factor that could lead to errors. Everyone loves a well-written script. Historically, scripts have been written mostly in Shell Script, Python, or Ruby languages. In recent years, however, Javascript started making its way into this universe. A good reason to use Javascript for this is the familiarity that most developers have with this language. However, a reason not to use it is that Javascript, in its purest form, is limited and inferior to the aforementioned languages, and it´s not easy to extend its functionality using external dependencies. Typescript can be seen as an evolution to Javascript, and it is even more complicated to create a Typescript script and run it from the command line. This scenario changed forever with the release of Deno 2.0 which makes running Javascript AND Typescript scripts natively, with support for external dependencies, a breeze. In this series of articles, we will explore the possibilities of creating Typescript scripts that use external libraries, such as those from Node's NPM or Deno's JSR, and running them using Deno 2. Then, for the sake of comparison, we will see how to achieve the same using Node.JS. The sample script The sample script is a simple command line interface (CLI) script that asks you some questions and then prints them formatted to the terminal, based on your input. Its purpose is to show you how to run a Typescript script that uses external dependencies from the command line. Head to the next page to see how to implement it using Deno 2.0

Jan 19, 2025 - 21:41
Typescript scripts in the command line: Deno 2.0 vs Node.JS

Whether you are new to the development world or a seasoned developer, scripts make life easier. They automate repetitive tasks, streamline complex processes, and produce predictable output, phasing out the human factor that could lead to errors. Everyone loves a well-written script.

Historically, scripts have been written mostly in Shell Script, Python, or Ruby languages. In recent years, however, Javascript started making its way into this universe. A good reason to use Javascript for this is the familiarity that most developers have with this language. However, a reason not to use it is that Javascript, in its purest form, is limited and inferior to the aforementioned languages, and it´s not easy to extend its functionality using external dependencies. Typescript can be seen as an evolution to Javascript, and it is even more complicated to create a Typescript script and run it from the command line.

This scenario changed forever with the release of Deno 2.0 which makes running Javascript AND Typescript scripts natively, with support for external dependencies, a breeze.

In this series of articles, we will explore the possibilities of creating Typescript scripts that use external libraries, such as those from Node's NPM or Deno's JSR, and running them using Deno 2. Then, for the sake of comparison, we will see how to achieve the same using Node.JS.

The sample script

The sample script is a simple command line interface (CLI) script that asks you some questions and then prints them formatted to the terminal, based on your input. Its purpose is to show you how to run a Typescript script that uses external dependencies from the command line.

Head to the next page to see how to implement it using Deno 2.0