In your new project folder, create a new
index.html file. In the
Start by adding the following code:
This code creates a basic HTML document with a title and a heading. The
console.log() function prints whatever is passed to it to the console.
By using the console, developers can log important information about their code, like variable values, function calls, and error messages. This helps them identify and fix any issues with their code, making it more reliable and effective.
To run the program, open the HTML file in your web browser and then open the Developer Tools of your web browser. If you're using Google Chrome, you can also use the following shortcut to open Developer Tools:
Windows and Linux: Press Ctrl + Shift + J Mac: Press Command + Option + J
Windows and Linux: Press Ctrl + Shift + K Mac: Press Command + Option + K
Windows: Not supported Mac: Press Command + Option + C
Additionally, you can also right-click on a web page and select "Inspect Element" to open the Developer Tools panel.
script tag to this file:
index.html again in the browser and open the console to check if "Hello World!" was printed.
To be able to use Node.js, you must download it first. Luckily installing Node.js is a straightforward process. Here are the steps you can follow:
node -vto check that Node.js is installed correctly. This should display the version of Node.js that you installed.
Now that you have Node installed, you can run
script.js inside Node using the
node <file_path> command.
Open a command prompt or terminal and navigate to the directory where the file is saved. Run the file using the following command:
Node.js will print "Hello World!" to the console.
Congratulations, you've just created your first "Hello World" program using Node.js!