Series: JavaScript 101
- About JavaScript 101
- Hello World in Web Browser
- Hello World in Node.js
- Variable in JavaScript
- Data Types in JavaScript
- Array in JavaScript
- Object in JavaScript
- Spread Operator in JavaScript
- Loops in JavaScript
- Conditional Statements in JavaScript
- Functions in JavaScript
- Object-Oriented Programming in JavaScript
Hello World in Node.js
In the previous article, we learned how to run the classic "Hello World" program in a web browser using the developer console.
Node.js is a platform that allows you to run JavaScript outside of a web browser. This means you have access to more system resources and can build more complex applications.
In this article, we'll go over how to install Node.js and write your first "Hello World" program using the Node.js environment.
Installation ⬇️
The first step is to download and install the Node.js setup file from the official website of Node.js. Simply click on the Download button and follow the instructions to install Node.js on your computer.
Once the installation is complete, you can verify if Node.js is installed by opening the command prompt or terminal and typing in the following command:
node -v
This will display the version of Node.js installed on your computer.
Start coding ⌨️
Now that Node.js is installed, it’s time to write your first program.
Open an IDE (or a text editor if you do not have an IDE) and create a new file called hello.js
. In this file, we will write the following code:
console.log("Hello World");
Save the file and open the command prompt or terminal. Navigate to the directory where the file is saved and type in the following command:
node hello.js
This will run the code and display the "Hello World" message on the screen.