beginner

Installing NodeJS


Starting out

In the beginning we will cover general Javascript code (even if I will refer to it as NodeJS) and later we will move onto NodeJS. In order to test our code locally we need to install NodeJS. You can also run Javascript code in your browsers terminal but we will need NodeJS later so lets just install it now.

Throughout the posts you’ll see (⏭️) which means that this topic will be handled in later posts.

Before you start I would advise downloading and using Visual Studio Code for writing your code. Create a file called index.js or any other filename ending with .js and you will write your code there. In VS Code you can open a terminal using Shift+Escape or clicking on View->Terminal and once you have NodeJS installed you can execute your .js files by running node <filename>.js in terminal.

What Exactly is NodeJS

While JavaScript shines in the browser, it was historically limited to client-side scripting meaning it could not run anything server-side. So NodeJS was created and its a runtime environment that enables the execution of Javascript code outside the browser, allowing developers to build scalable server-side applications. NodeJS is designed with an event-driven architecture(⏭️), making it highly efficient for handling asynchronous operations. This non-blocking I/O (Input/Output) model ensures that the server can handle many simultaneous connections without waiting for one to complete before moving on to the next. Put simply, NodeJS allows us to run Javascript on the backend side and it is very fast.

Download NodeJS

The first step is to download NodeJS from the official website: nodejs.org. Some versions of NodeJS have “LTS” which means “Long Term Support” and they are the ones that are usually used for running web servers because they receive long term support as the name suggests. Other versions, that might be newer, are usually used for personal project or projects where newer features are introduced and needed.

This can also be done through volta that makes it possible to have multiple versions of NodeJS installed and then switch them based on project needs. This is advised way to have node installed locally but you can install it through offical website if that is easier for you. Below are steps for offical installer.

  • For Windows:

    • Download the Windows Installer.
    • Run the installer and follow the on-screen instructions.
    • You may need to restart your computer after installation.
  • For macOS:

    • Download the macOS Installer.
    • Run the installer and follow the on-screen instructions.
  • For Linux:

    • NodeJS can be installed on Linux using package managers. For example, on Ubuntu, you can use:

      sudo apt-get update
      sudo apt-get install nodejs

      The package manager will also install npm, the NodeJS package manager. This helps you use built-in modules or modules created by other people or share your own. There are other package managers but for now we will use npm.

Verify the Installation

Once the installation is complete, you can verify that NodeJS and npm are properly installed by running the following commands in your terminal or command prompt:

node -v
npm -v

These commands should print out the installed versions of NodeJS and npm, confirming that the installation was successful.

Update npm (Optional)

npm is frequently updated with new features and bug fixes. It’s a good practice to update npm to the latest version using the following command:

npm install -g npm

This command installs the latest version of npm globally on your machine.

Previous Glossary
Next Variables and data types