Let's see how you can create your first Node.js application. This section will show you how to run Node.js scripts from the command line.
How to download and install Node.js
First, you need to download and install Node.js. There are different ways you can do that. If you are a beginner, I suggest downloading Node.js from the official website.
[image]
Official packages are available on the website for all major platforms (Windows, macOS, and Linux). Download and install the appropriate package for your system.
After installing Node.js successfully, open your terminal and type the following command to confirm your installation.
node -v
If you see Node.js with version information as shown below, then you have successfully installed Node.js on your machine.
You can also confirm the version of NPM (Node Package Manager) that’s installed using the command below:
npm -v
NPM is always installed with a fresh version of Node.js; you don’t need to install it separately.
Create your first Node Application.
Now that you have Node installed let’s create our first Node application, open any text editor of your choice and type the following scripts in a new index.js
file.
console.log("Hello World")
Next, open your terminal to the location of your index.js
file and type the following command to compile and run your code:
node index.js
If everything is successful, you should be greeted with Hello World
in your terminal as the output.
Of course, Node doesn’t end there. Next, let’s explore Node.js modules and look at some of the popular Node.js modules.