DonJayamanne / typescript-notebook

Run JavaScript and TypeScript in node.js within VS Code notebooks with excellent support for debugging, tensorflowjs visulizations, plotly, danfojs, etc
https://marketplace.visualstudio.com/items?itemName=donjayamanne.typescript-notebook
MIT License
904 stars 39 forks source link

Readline (user input) usage #45

Open jaeggerr opened 2 years ago

jaeggerr commented 2 years ago

Hello!

First of all, I'd like to thank you a lot for this awesome project. I've been waiting for years for a tool like Jupyter in Visual Studio Code for Node development.

Could you provide an example of how to get the user input? I tried different ways to use readline without any success.

Other question. Is there a way to input a file? I was thinking of using HTML but could not find a way to communicate between the JavaScript from HTML cells and the the JavasScript from the notebook.

andrewtacon commented 2 years ago

Hi, I ran this from https://node.readthedocs.io/en/latest/api/readline/ and it works. The prompt input box appears at the top of the IDE as a dropdown.

var readline = require('readline');

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

rl.question("What do you think of node.js? ", function(answer) { // TODO: Log the answer in a database console.log("Thank you for your valuable feedback:", answer);

rl.close(); });