Let age = prompt("Enter your age"); console.log(typeof age); WHY IS THIS NOT WORKING IN REPLIT

Question:

Current behavior:

Desired behavior

Repl link:

code snippet

Welcome to Replit Ask!

The prompt function does not exist in Node.js - it was a feature with Replit’s Prybar which has now been discontinued.

To get user input, you can use the node:readline module:

const readline = require('node:readline');

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

rl.question('Enter your age  ', (age) => {
  console.log(typeof age);
});

If you feel like my answer has solved your question, feel free to mark it as the solution by pressing the Solution button!

2 Likes

Hi @HarshChaudhar25 ,welcome to the forums!
This was an update, so you’ll need to use the prompt-sync library.

const prompt = require('prompt-sync')()
prompt('Enter your name: ')

Hope this helps!

@haroon idk why your one is soo compicated, tbh.

2 Likes

Readline is a core Node.js package, which means end users won’t have to download the prompt-sync library for the code to work (I get this is Replit, but let’s say someone downloads the code and runs it on their machine with no internet, it wouldn’t work unless it was downloaded already)

Also node_modules is bloat

4 Likes