DEV Community

Kai
Kai

Posted on • Originally published at kais.blog

How to Install Node.js and npm on Windows or macOS

This post was originally published at kais.blog.

Let's move your learning forward together! Follow me on Twitter for your daily dose of developer tips. Thanks for reading my content!


Installing Node.js and npm on Windows or macOS is an easy task. Learn how to do it within a few minutes.

What are Node.js and npm?

Node.js is a JavaScript runtime that allows you to execute programs written in JavaScript. With Node.js JavaScript is not restricted to the browser anymore. In fact, by using Node.js you can create web, mobile and desktop apps. It's awesome! You should give it a try!

npm (originally short for Node Package Manager) is a command-line-utility that's included with your Node.js installation. It acts as a package manager for JavaScript. With npm you can download so-called packages from a package registry (most of the time - the npm registry). These packages are provided by other developers and help you develop your applications. You can also publish your own packages and thus, share your code and take part in the community.

How to Install Node.js and npm

Step 1: Download and Run the Node.js Installer

First, you have to download the installer. Navigate to:

https://nodejs.org/en/download/

Click the Windows Installer or macOS Installer button. This starts downloading the latest, recommended Node.js version for Windows / macOS. Once the installer has finished downloading, you are ready to run it. So, browse to the location where you have saved the file and run the installer.

The installer will guide you through the steps. You can leave it with the defaults. When the installer has finished the installation, you are ready to use Node.js. Let's verify that everything works as intended in the next step.

Step 2: Verify Your Node.js Installation

After running the installer for Node.js, you should have access to the node and the npm command-line-utilities. Let's try it! Open the Windows Command Prompt / Windows PowerShell or Terminal (macOS). Enter the following:

node -v
Enter fullscreen mode Exit fullscreen mode

Now, you should see the current Node.js version installed on your system. Let's try the same for npm:

npm -v
Enter fullscreen mode Exit fullscreen mode

This should show you the current npm version on your system. If everything works, you are ready to create your first simple Node.js program. If you see an error, try restarting your computer. Then, try again.

Step 3: Create Your First Node.js Program

Now that you have successfully installed Node.js and npm on your computer, you are ready to create your first Node.js program. Launch a text editor of your choice. Write the following line of JavaScript into a new file:

console.log("Hello, world!");
Enter fullscreen mode Exit fullscreen mode

Now, save that file and name it hello.js. Open your Windows Command Prompt / PowerShell or Terminal (macOS). Use it to navigate to the place where you've saved the file. Then, type in the following:

node hello.js
Enter fullscreen mode Exit fullscreen mode

You should see Hello, world!. Nice! You've successfully created your first Node.js program. As you can see, you've executed JavaScript on your computer. Well, there's far too much to show you now. Just let me tell you something - learning Node.js is a valuable skill. You can create web, mobile and desktop apps with it. Even games!

Have fun learning! See you around!


Let's move your learning forward together! Follow me on Twitter for your daily dose of developer tips. Thanks for reading my content!

This post was originally published at kais.blog.

Top comments (0)