Hey guys, so hope you had a good week. Let’s crack on something that’s exciting as in doing some hands-on work. Let’s begin this time by installing Node JS. Point your browser to NodeJS Website and please download one of the following versions on to your computer. You’ll be shown with the following two versions:
There’s version 8.9.4 and 9.6.1 at the time of writing this story. The difference between the two is, the one that says LTS, it stands for Long Term Support, and it’s the latest stable version. The one on the right is although the latest version, having all the ground-breaking features, it’s really breaking. Just kidding, it’s with the latest features but it may not be always stable and it’s not meant to be used for production. So, for most of the developers out there, I am going to recommend you to go for the LTS version.
Get the installer edition, go through the installation steps, don’t change the default parameters and just complete the installation. It takes about three minutes for the whole installation to complete and Node JS will be installed.
Checking for Node JS Installation
After installation, we need to make sure if the Node JS is really installed. To check that, you can run a simple command from the command line. You can access the command line in most popular operating systems in the following ways:
Open the Start Menu and type cmd. Press Enter to open the command prompt.
Open your Spotlight Search and type terminal. Press Return to open the terminal application.
Open Terminal in the Applications. You will be able to see the terminal window opened.
Once you open the command prompt or terminal, if you enter the following command:
This is going to tell the node version that’s been installed in your system. In my PC, it’s something like this:
So, if you have been successful installing node, it’s going to return you the version of Node JS that’s been installed in your system. I have got the latest stable version on my computer, when writing this article. So, if you do the same in your PC, it might be different. When I wrote one of the pre-requisites in my previous tutorial about knowing a little bit of command line, this is what I meant.
Whenever we need to run an application in node or do something in node, we are going to write a command in the command line using terminal.
Your first Node JS Application
Open up a directory of your choice and create a new file called app.js. The only content you should be having inside it should be the following:
Once you have saved the file as app.js, you have to run the file using node. To run it, you just need to fire up a command line and run the following command:
You should be getting a similar output like this:
Make sure you are in the same directory in the command prompt where the app.js file is residing. You can easily change the directory in command line this way. Let’s consider a scenario where your app.js file is located in a directory named “Node-Stuff” in your Desktop. In Windows, when you open up your command prompt, you will be taken to your profile home directory.
Your “Desktop” is also a directory under your profile home directory, which, in Windows, generally stays at
See the commands that are needed to go to your application directory and run the application:
That should have been fairly simple. This is the most simple way to run a node command line application. Also, if you want to know how to navigate through different directories in the command line, you have to use the cd command.
See above, it doesn’t use app.js but just app. Cool, isn’t it? It gives the same output.
We have successfully installed Node and we ran our first Node JS application, even though it was a small Hello World application. We’ll be getting to run some advanced Node JS applications in the next articles. Until then, have fun! ☺
Thanks to Praveen Kumar for being our guest writer this week.