Say you want to run / debug a HackerRank solution locally on your WebStorm / IntelliJ Idea IDE for for macOS before submitting it. What are the needed steps, considering node.js is already installed in your machine?
Sample Hello.js file as below:
const fs = require('fs');
function processData(input) {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
var i, result = "";
for (i = 0; i < parseInt(input); i++) {
result += 'Hello - ' + i + 'n';
}
ws.write(result + "n");
ws.end();
}
process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
_input += input;
});
process.stdin.on("end", function () {
processData(_input);
});
Advertisement
Answer
On macOS Mojave the steps are:
- On Preferences > Keymap, add a keyboard shortcut
Ctrl+Dto run the Other > Send EOF action; beware this may remove other actions associated to this shortcut, such as “Debug” (credits to this answer) - Add the
Hello.jsfile to your project and open it in the editor - Enter
Modify Run Configuration...dialog (Cmd+Shift+A`, type “modify …” and select it)- make sure
Node interpreter:,Working directory:andJavaScript file:are properly set - (if the solution writes output to a file) Set also the
Environment variables:toOUTPUT_PATH=./hello.txtor as desired - Save it
- make sure
- Run the configuration. In the terminal pane that opens:
- provide the needed input; e.g. 4, then Enter
- press Ctrl+D to fire the
"end"event - check the generated file
hello.txt
You may want to use console.log() to help debugging; make sure it’s commented out before submitting your solution back to HackerRank.
Run Configuration:
Run Tool Window:

