Cannot find name "process" in simple input script

312 views Asked by At

I am starting to work with deno and typescript, and after some experimentation I figured out how to import code from other modules and such, and now I needed to create a simple script to take a given input in the console and then output a particular message depending on the message. I realize that this has something to do with dependencies and what the compiler looks for, but I'm really not sure how to set it up. Here is my code in its entirety:

import * as readline from './node_modules/readline/readline.js';

let rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.question('yes or no bitch', (answer:any) => {
  switch(answer.toLowerCase()) {
    case 'y':
      console.log('noice');
      break;
    case 'n':
      console.log("okay bitch");
      break;
    default:
      console.log("no.");
  }
  rl.close();
});

And here is the error I am getting: enter image description here

What is required for me to fix this

Edit: I had already run npm i @types/node previous to this screenshot, and it did not change anything.

1

There are 1 answers

0
Ramon Medeiros On BEST ANSWER

If you want to read stdin from Deno, you can use this standard library readlines. Here is a snippet:

import { readLines } from "https://deno.land/std/io/buffer.ts";

for await (const line of readLines(Deno.stdin)) {
   switch(line.toLowerCase()) {
    case 'y':
      console.log('noice');
      break;
    case 'n':
      console.log("okay bitch");
      break;
    default:
      console.log("no.");
  }
}

Also, you can import old modules like you did in your snippet, but Deno support this imports from a url, which is much more easy