Quote:
I have node installed
How do you intend to do that? Like this,
alert("Node.js installed");
If so, that is a bad design and experience for the user, I can say this much.
What I would recommend is going back to creating an HTML file, and showing that file in Chrome (or any locally installed browser) and stating that Node.js has been installed. One thing to notice here is that you can use HTML, because you do not need to execute any code to check whether Node.js is installed or not, since you are executing this code from Node.js.
Quote:
I clicked file.js but only code of file displayed
There are securities in browsers, that would prevent the JavaScript code to be executed if you open a file directly. That is why you load this file directly in a
script
element so the browser can execute the code.
Thus, a good approach is to utilize the standard HTML file and show the content. One more thing, you can always insert the JavaScript in this HTML file using the
script
element.
Quote:
I was expecting output to be displayed like it displays in CMD when I type 'node file.js'
When you execute the node binary, that is not your browser or any JavaScript engine (I know, V8 is a JavaScript engine too) executing anything instead that is the Node.js executable running your code and logging the outputs of your application. If it is the logs that you want to see, you can maintain a connection between your Node.js process and that browser window and show the logs there.
You can try to pipe the output to other windows, such as browsers and tabs in the browser and have all the logs forwarded there, or maybe write it somewhere from where your browser or JavaScript will read and show in the tab. Maybe?