简体   繁体   中英

Run node js with input from console in Sublime text

I want to running Javascript code with an input from console. I have followed this tutorial to run the program by node js ( https://pawelgrzybek.com/javascript-console-in-sublime-text/ ) but I can't find how to put the input element in Sublime text.

1) Add your input to the command: "cmd": ["/usr/bin/nodejs", "$file", "This is my input"]

2) get the input by: process.argv[index]

Check my screen shot

Is this what you asking for?

UPDATE:

I dont find anyway to pass a variable during the build: Ref: http://docs.sublimetext.info/en/latest/reference/build_systems/configuration.html#variants

In your case, we still can edit javaScript.sublime-build to see the result interactively(not limit inputs number). Something like this: "cmd": ["/usr/bin/nodejs", "$file", "This is my input", "2nd", "3nd", "put as many as you want"],

You cannot pass input to the console. What you need is a REPL, for instance SublimeREPL . Once installed, you can launch “SublimeREPL: Node” from the command palette.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM