M Logo
๐Ÿ“ TypeScript from Zero ยท Part 12 of 50

TypeScript Reading Input: process.argv, readline and @types/node

November 6, 2026

Welcome to episode 12 of TypeScript from Zero, a series for complete beginners (no JavaScript needed). Welcome back to TypeScript from zero! Today our programs listen. We read words from the command line, and we ask the user a question and wait for the answer. We continue in the shop project. A new file called args.ts. Every code block below is the code from the video, ready to copy; run each file to see the output.

Setup

We start in the terminal and open the project in VS Code:

bash
$ touch src/args.ts

1. argv

Node gives us the command line words in process dot argv. The first two items are Node itself and our file, so we cut them off with slice two. Now we run the file and add two words after it: Mia and thirty. They arrive as a list of texts. Even the thirty is text.

ts
const args = process.argv.slice(2);
console.log(args);
bash
$ node src/args.ts Mia 30

2. Error

But tsc complains: cannot find name process. The code is TS2591, and it even tells us what to do. TypeScript does not know the Node world by default, so we have to teach it.

bash
$ npx tsc --noEmit

3. Install

First we install the types for Node: npm install, -- save dash dev, at types slash node. A types package only holds descriptions, no code.

bash
$ npm install --save-dev @types/node

4. Config

Then, in tsconfig.json, we add node to the types list.

5. Quiet

Now tsc is quiet. It knows process, and every other Node feature.

bash
$ npx tsc --noEmit

6. Readline

Now a question for the user. We import readline promises from Node. We create an interface with the keyboard as input and the screen as output. Await waits until the user presses enter, and at the end we close the interface.

bash
$ touch src/ask.ts
ts
import * as readline from "node:readline/promises";
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
const answer = await rl.question("Your name? ");
console.log("Hello, " + answer);
rl.close();
bash
$ npx tsc --noEmit

7. Run

We run it. It asks for our name. We type Mia, press enter, and the program greets us.

bash
$ node src/ask.ts
bash
$ Mia

Recap

Today: process dot argv for command line words, the error when types are missing, at types slash node plus the types setting, and readline to ask a question. Next episode: type annotations and inference.

ยฉ 2026 All Rights Reserved By Mahmudul Alam