Deno run

In this lesson, we will look at running a file using the Deno executable

import {Terminal, Text, Command, Space} from '~/mdx/Terminal'

Deno run

In this second part of the lesson, we will create a file and run it using Deno. In our directory, we will create a file called main.ts. If you are coming from JavaScript, there are two things you might be wondering about - why this file is called main and not index, and why the file has the .ts extension instead of .js.

The reasons are simple: Deno is built in Rust, which means that a lot of the conventions come from the better practices of Rust and not the (debatably worse) practices of Node. index has a lot of expectations in terms of how it works which is not applicable for Deno (you wont be able to access a file at demo/index.js by importing demo). We use ts because of Deno's native support for TypeScript as it parses the code to JavaScript and caches it before running the code.

Deno can handle js, ts, jsx, and tsx files as it parses TypeScript and runs JavaScript

However, you don't have to name your files according to any specific naming convention; after all, it's your program! You can call it whatever you like. Here is the Deno style guide if you want to learn more. Common names for entry files looks like follows:

FilenameDescription
main.tsUsed by applications to signify the main entry point and where to load the application from
mod.tsUsed by modules as an entry point to signify from where to load components
cli.tsUsed by modules where a command-line interface is available and serves as an entry point to the CLI
lib.tsNot as widely used as the prior three, but commonly used as an entry point for internally used components, e.g. used by cli.ts or mod.ts.
 

This page is a preview of Build and deploy a REST API with Deno

Start a new discussion. All notification go to the author.