6.2 Hello world program v2
TS and JS code
We'll continue to use Typescript for our examples. The program is the same, with some additions:
There are two imports with one import has another inside it
There is a synchronous op
There is an asynchronous op
Also, there are some console logs which are also synchronous ops
The file name is helloV2.ts.
The location of the source file is:
/Users/mayankc/Work/source/denoExamples/helloV2.ts
Here is the code that we'll use to understand some new concepts:
This remains a straightforward program consisting of a single TypeScript file. At the program's outset, two imports are used to access ES modules:
nanoid
machine_id
The 'nanoid' module is sourced from the NPM registry, while the 'machine_id' module is acquired from Deno's registry.
The program can be partitioned into three distinct segments:
Import Section: The initial portion encompasses the two imports, serving the purpose of illustrating the internal mechanics of the import process.
Synchronous and Asynchronous Operations: This phase involves invocations of both synchronous and asynchronous operations. The operations involving 'nanoid' and 'env.get' are categorized as synchronous, whereas the 'getMachineId' operation is asynchronous in nature.
TypeScript Code: The subsequent part entails the inclusion of code extracted from 'helloLog.ts', showcasing the conversion process from TypeScript to JavaScript. This step is taken to offer a demonstration of how TypeScript code translates into its JavaScript equivalent.
Following the conversion to JavaScript, the program's structure transforms as illustrated below:
This section discusses the similarities and slight differences in the current version of the 'hello world' program compared to the previous one. The primary changes revolve around imports and operations (ops). It's worth noting that some ops, like console.log
, were present in the previous version as well.
--
Let's take a moment to review. The primary worker in Deno operates through two main phases:
Module loading
Module evaluation
The process of loading a module can vary due to the presence of imports.
Now, we will discuss creating a module graph for a program with imports. This involves showing how modules connect and interact in a program.
To create a module graph, Deno analyzes the code to find all imported modules and their dependencies. It then organizes these modules in a structured way, showing their connections.
Last updated