How to Install Node.JS and NPM on Windows, Mac or Linux

This post will show you how to install Node.js and NPM on Windows, Mac, or Linux in under 15 minutes.

Nodes are an open source runtime environment for JavaScript. It is a cross-platform environment that supports Windows, Mac and Linux. It is very powerful because it runs Chrome’s V8 JavaScript engine outside of the browser.
How to Install NodeJS
It runs as a single process without creating a new thread for each request. Node JS

What is Node.js?

The first thing to know is that Node.js is not a programming language.

You may already know this, but it bears repeating for developers new to this field who may confuse Node.js with their own programming language. it’s not!

Node.js is an open source runtime environment for the JavaScript language that rebuilds the properties of updates its functionality and JavaScript. As a result, you can use JavaScript for back-end and front-end development, enabling full-stack development using only JavaScript.

Initially, Node.js was designed with a real-time pushback architecture to provide performance. But since then Node.js has become an important part for non-blocking event-based servers of server-side programming. Most traditional websites and API services today rely on Node.js.

Prior to Node.js, server-side language support was required when connecting programs to database or archiving data to database. This is because JavaScript could not tune the backend process. As a result, I had to learn server-side languages ​​such as Python, Ruby, PHP and C #, or seek help from backend developers.

In the Node.js environment, JavaScript can work fine as backend language and use the database directly. Therefore, you can write programs and run in Node.js using only JavaScript.

Node.js uses the JavaScript V8 runtime engine as the root feed and uses an event-based, non-blocking I / O architecture. All of this helps to robust performance to build Node.js together and drive the product.

Who Uses Node.js?

So far 1.4% of all websites are using Node.js, according to W3Techs. That’s over 22 million websites. These numbers give you an idea of users of Node.js of ​​the number. Additionally, Node.js has been downloaded over 1.3 billion times! As you can see, stats like the size of the Node.js market.

Everyone to industry mogul enjoys Node.js from computer friends. This is because Node.js speeds up the development process and improves developer performance. Everywhere one of the smartest trends these days is to use JavaScript. With that, Node.js has arrived.

Top 10 main companies are using Node.js:

  • Nasa
  • LinkedIn
  • Mozilla
  • Moderate
  • Pay Pal
  • Trello
  • Twitter
  • Netflix
  • eBay
  • Walmart

If you study these companies, you might find that they operate in a variety of services and products. However, there is one important factor in common with all of these. It depends on Node.js. In fact, Node.js can solve most of your development problems in any industry.

Installation of NodeJS and NPM

NodeJS and NPM installation is easy with the installation packages available on the official Node.JS website.

  • Download the installer from the Node.JS website.
  • Run the installer.
  • Follow the installer instructions to accept the license agreement and click the Next button.
  • Restart your system / machine.

Then test NodeJS by printing the version using the following command at the command prompt:

> Node -v

Test npm by printing the version using a command

> npm -v

An easy way to test Node.JS behavior on your system is to create a JavaScript file that outputs the message.

Let’s create a test.js file

/ * test1.js file * /
console.log ("Node is now running");

Run the test1.js file using the Node command > node test1.js at the command prompt.

The installation is complete.

Node package module

NPM is a package module that helps JavaScript developers load dependencies effectively. To load dependencies, you need to run the command at the command prompt.

> npm install

This command looks in the root directory for a json file named package.json and installs all dependencies defined in the file.

How to Install Node.js on Windows and MAC

To download the node, you need to go to the official website of the node and download the LTS version of the node.

  • Once downloaded, an installer similar to this one.
  • Tap Install when installing other apps on Windows or Mac. Enter your system password when prompted.
  • When this is done, the installer will ask for a success message. You can now go ahead and remove the installer.

How to Install on Linux

To install Node.js on your Ubuntu computer, run the following command:
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - sudo apt-get install -y nodejs

When you download a node.js, NPM or Node Package Manager ships with the node and will be installed automatically.

Install a text editor

Then install a text editor to help you write your code. My personal use is Microsoft’s Visual Studio code.

You can download it here: https://code.visualstudio.com/

After using the text editor the next thing you can do is check if the node path is correct.

Testing Node.js and installing NPM

You can verify the node installation by simply running the smallnode command, which displays the installed version. Just open cmd or PowerShell and paste the following command. This will display the version of the node installed on your computer.

Node -v
v12.16.0

Likewise, you can see the version of npm installed on your computer. You can check the version by simply pasting the following node command.

npm -v
v6.13.4

Run the First Application

Everything is ready. Let’s run a small server node. Open VS Code, create a new file and save it as app.js
Paste the following code.

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
});

server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});

Save the code and press Ctrl + ~.

This will open an embedded terminal vs code in the same directory where you can run your js code directly.

Just run the following command and hit enter.

node app.js
Server running at http://127.0.0.1:3000/

You can now go to http: //127.0.0.1:3000/ to see the running node application.

Well it was about setting up the system for js development. If you get any errors, try searching on Google and debugging yourself.

Conclusion

You can now install both the Node.js framework and the NPM package manager. You also wrote the first node.js JavaScript program!. If you still can’t find a solution to your problem, ask in the comments section below. I’ll call you back.