I recently posted a introduction to Deno where I walk through how to get Deno installed and the features I think make it an exciting project. The next step for me was to start building something with Deno.
The first project I took a look at was a node script I used to generate new blog posts in Gridsome. Before I tackle the entire script I want to use this tutorial to discuss how you can work with standard input and output in Deno.
Before you write any code I think it is important for you to understand what standard in and standard out are. Standard output, sometimes abbreviated stdout
, refers to the standardized stream to which a program writes its output data. Standard input, sometimes abbreviated stdin
is a stream from which a program reads its input data. Without getting into low level abstractions this is way to read and write data.
Now that you have an understanding of what standard in & out are let’s talk about them in the context of Deno. If you want to get a handle for [stdin](https://doc.deno.land/https/github.com/denoland/deno/releases/latest/download/lib.deno.d.ts#Deno.stdin)
or [stdout](https://doc.deno.land/https/github.com/denoland/deno/releases/latest/download/lib.deno.d.ts#Deno.stdout)
you can use the properties from the Deno Runtime API:
Deno.stdin;
Deno.stdout;
If you take a look at the source for Deno you will see the following:
/** A handle for `stdin`. */
export const stdin: Reader & ReaderSync & Closer & { rid: number };
/** A handle for `stdout`. */
export const stdout: Writer & WriterSync & Closer & { rid: number };
If you’re new to TypeScript that probably looks a little confusing but don’t let it scare you. Deno is declaring a variable called stdin
that is a type that combines Reader
, ReaderSync
and Closer
and an object with a property called rid. In TypeScript these are called Intersection Types and they are pretty darn cool once you start using them.
#deno #node #javascript #typescript #web-development