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.
- All episodes are in the TypeScript from Zero playlist.
- Versions used: Node.js 26.13.0, npm 11.20.0, TypeScript 7.0.2.
Setup
We start in the terminal and open the project in VS Code:
$ touch src/args.ts1. 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.
const args = process.argv.slice(2);
console.log(args);$ node src/args.ts Mia 302. 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.
$ npx tsc --noEmit3. 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.
$ npm install --save-dev @types/node4. 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.
$ npx tsc --noEmit6. 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.
$ touch src/ask.tsimport * 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();$ npx tsc --noEmit7. Run
We run it. It asks for our name. We type Mia, press enter, and the program greets us.
$ node src/ask.ts$ MiaRecap
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.