TechTalkers
Published in

TechTalkers

Getting Started With Node.js

Learn how to download, setup, and run Node.js on your computer.

Summary of the use-cases of Node.js (Picture Credit: Simform)

In this tutorial, I will be walking you through the steps needed to start building apps with Node.js. I assume that you already know the basics of JavaScript, but if you need a refresher, sites like the MDN documentation and W3Schools are great places to review your knowledge.

What is Node.js?

Released in 2009, Node.js has revolutionized the way servers are programmed by developers. Before the creation of Node.js, servers were programmed using languages like PHP or Ruby. Now you can use JavaScript, a programming language meant to be used in the frontend, to write server code. Thanks to Node.js, developing full-stack applications has become much easier for developers.

According to the official Node.js website, “Node.js® is a JavaScript runtime built on Chrome’s V8 JavaScript engine.”

Let’s take a look at what this means step-by-step.

A JavaScript runtime is an environment where your JavaScript code is executed. It provides utility libraries and other tools that can be used when your code is ready to execute.

A JavaScript engine, on the other hand, acts as a translator between the client and the user’s CPU. Since CPUs cannot natively execute JavaScript, it is the JavaScript engine’s job to compile your JS code into machine code, which can then be executed by the CPU.

Now, let’s take a look at how you can download this JavaScript runtime on your own computer.

Step 1: Download Node.js

The Node.js downloads page

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.

Download the correct version of Node.js from the official website

Step 2: Run the Installer

You should see a welcome screen that looks similar to this when you open the installer:

Node.js Setup Wizard

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:

Open the terminal on Windows

On macOS, typing “terminal” into Spotlight Search should bring up the terminal.

Verify that Node.js and NPM are installed on your computer

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

Note: This step is completely optional but is useful if you want to know how you can run JavaScript files using Node.js.

Create an app.js file in your favorite text editor

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.

Type console.log(“Hello World”) in the app.js file

Next, type console.log(“Hello World”) into your app.js file. If you don’t know JavaScript, this line of code simply prints “Hello World” into the console. Make sure to save the file before running it.

It’s finally time to run your first Node.js program! Normally, to run the app.js file, you would have to link it up to an HTML file and open it in a browser. But now, that isn’t necessary because Node.js includes its own JavaScript runtime.

Navigate to the folder your app.js file resides in and run node app.js

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:

  • Node.js is a JavaScript runtime that uses Chrome’s V8 JavaScript engine.
  • A JavaScript runtime is an environment where your JavaScript code executes.
  • A JavaScript engine translates your JavaScript into machine code, which can be read by the CPU.
  • Once you have installed Node.js, you can run JavaScript files by typing “node <filename>” where filename is the name of the JavaScript file you want to run.

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.

--

--

--

Posting articles about the most interesting science and tech innovations. Follow to keep up with the constantly changing worlds of science and technology.

Recommended from Medium

Why is local development of npm packages so hard?

State Management: Mobx vsRedux

Hello there, my name is name rashed.

Writing a Front End Component With Vanilla JS

Advantages of ReactJS and why you should choose it for your project

Top Hybrid Mobile App Framework

The JavaScript Journey: I Need More Coffee ☕

Why React should be your choice for web application development.

Why React should be your choice for web application development?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Advaith Malka

Advaith Malka

I like to write about whatever wakes up my mind.

More from Medium

File Minification and Concatenation with Grunt for Node.js Applications

Prisma: ORMs hightlight in Node.js

[JavaScript Series] How to install Node.js on your PC/Laptop