Getting Started With Node.js
Learn how to download, setup, and run Node.js on your computer.
What is Node.js?
Let’s take a look at what this means step-by-step.
Step 1: Download Node.js
First, before you install Node.js, you need to make sure you have admin privileges to your system (make sure you can download and open programs on your computer). Then, you can go over to the official Node.js downloads page and download the installer suitable for your operating system. When you head over there, you will see two different versions of Node: LTS (Long Term Support) and Current. LTS is the most stable and tested version, while Current includes new features that are under active development. I would recommend installing LTS because it is usually the most bug-free and suitable for production. Since I am on Windows, I downloaded the Windows installer, but if you are on macOS, the setup should be pretty similar.
Step 2: Run the Installer
You should see a welcome screen that looks similar to this when you open the installer:
After you click next, accept the TOS, and select the destination folder, you should see this screen:
The default options are suitable for most developers, but if you need to change something, make sure you know what you are doing.
After clicking Next, this screen should show up:
This screen should be asking you if you want to install Python and Visual Studio Build tools. If you know that you will be working with C or C++ modules, go ahead and check the box, otherwise, you should leave it unchecked.
You can learn more about native Node modules here.
The next screen should install Node onto your computer:
Step 3: Verify the Installation
Next, to make sure that Node.js is properly installed, we need to make sure your computer recognizes Node. We can do this by running the node command in the terminal.
If you are on Windows, you can run the terminal by searching “cmd” in the start menu:
On macOS, typing “terminal” into Spotlight Search should bring up the terminal.
After the terminal has opened, verify the installation of Node.js by typing “node -v”. This command should print out the version of Node installed on your computer. In my case, I have Node version 14.15.1 installed. Subsequently, verify NPM is installed by running “npm -v” in the terminal. NPM is a package manager that comes with Node.js, which you can learn more about here.
If any of these commands yield an error to be displayed, make sure you close other programs that might be affecting the installation and re-download Node.js.
Step 4: Hello World
First, open your favorite text editor and create an app.js file. If you don’t have a text editor already, some popular choices include Visual Studio Code, Atom, and Notepad++. Personally, I use Visual Studio Code because of its wide variety of extensions and large community.
To run your app.js file using Node, navigate to the directory (folder) your app.js file is located. You can change directories by typing cd followed by the relative path to your app.js file. Then, type “node app.js” into the terminal to run the app.js file. If you have followed the steps correctly, you should see “Hello World” printed into the terminal. Congratulations! You just ran your first Node.js program!
Let’s wrap up everything you learned in this article:
Your Node.js journey has just started! There is still a lot more you can learn, like using require to use NPM modules and tons of other APIs built by other developers like you. While Node.js might seem like the all-perfect framework/runtime to build server-side applications, it does have some limitations, one of them being resource use. Even if your computer or server has a multi-threaded CPU, Node.js cannot take advantage of every thread. This is because Node.js doesn’t support multi-threaded programming yet. As a result, CPU intensive applications might not perform well, even on powerful servers. Nevertheless, Node.js is a great tool to have in your tool-box, and thanks to its vast community, the possibilities the limitless.