There are the following steps you must have to do in order to run your code in any browser.
Write HTML Code
Write the HTML code like:
<!DOCTYPE html> <head> </head> <body> </body> </html>
Add Script To HTML file
Add script to either the
head of the HTML file, or the
body or make another file and reference it from your HTML document.
Disadvantages and Distractions
The disadvantages of the above strategy to write a stand-alone application or for learning are unmistakable. Most of the programmers get distracted and first declare fields to show their results. Although they might have nothing to do with their applications. Few try to beautify their page first using CSS, and the rest of people gets frustrated about inspecting the page by right clicking on it, and checking the console over and over again. Such a tedious task can have a negative effect on your progress. That's for any other article.
Let us break it down in multiple steps.
Step 1: Download Node.JS
You would only need one thing, which is
Node.js. First you need to download
node.js by going to the following link:
There will be two versions available. Download the latest Current version of Node.js. That's it for the downloading part.
Step 2: Install Node.JS
Install the downloaded copy of
node.js. The steps of installations are pretty straightforward and self-explanatory. Just press NEXT, NEXT etc. you will eventually finish the installation part of it.
Step 3: Make Folder and Create .js Document
Step 4: Run npm command
Open Command Prompt! Click the search windows and type cmd and hit enter.
The CMD would look like this:
And navigate to the folder using the following command line:
cd yourDirectory cd yourFolder
cd = Change Directory.
You can do the above two steps in one step, but to make things easy for you, I have broken down into two steps. I have made "NodeJS" folder on Desktop, and created "javanode.js" file in it. The above commands would look like this: After doing the above mentioned steps, run the following command on Command Prompt(CMD):
And the just press Enter multiple times upon names, versions etc. If you want to give them name, go for it. But for now I skipped that. At the end, you will be asked to type yes. Just type yes. That's it for the setting up. The commands would look like this:
Let's test it!
Write the following code in your
var a = 10; var b = 20; console.log(a+b);
And save it!
Go back to the command prompt, and type the following command:
This post is curated by IssueHunt that an issue based bounty for open-source projects.