Node.js Installation on Windows and Ubuntu

Node.js is an extremely powerful JavaScript-based server-side platform used to develop I/O intensive web applications like video streaming sites, single-page applications, online chat applications, and other web applications. 

Node.js is used by large, established companies (Netflix, Paypal, NASA, and Walmart, to name a few) and newly-minted startups alike. The platform brings plenty of advantages to the table, making it a better choice than other server-side platforms like Java or PHP in many cases.

The following article covers the complete Node.js installation on Windows and Ubuntu. We’ll also create a basic Node.js server, in the end, to verify if everything is working properly.

Enroll for the Node.js Certification Training and learn to build network applications quickly and efficiently using JavaScript. Check out the course curriculum!

Node.js Installation on Windows

In this section, we'll be looking at Node.js installation on Windows. If you're an Ubuntu user, you can jump ahead to the next section that deals with Node.js installation on Ubuntu.

Steps to Install on Windows:

1. Download Node.js from https://nodejs.org/en/download/

2. Select the Windows installer according to your system environment (32-bit or 64-bit).

downloads

3. Run the downloaded Node.js installer. 

4. Accept the license agreement. You can leave other settings as default. The installer will install Node.js and prompt you to click on the finish button.

node-js-setup

5. Verify that Node.js was properly installed by opening the command prompt and typing this command: node --version

node-version

6. When we install Node.js, NPM (Node Package Manager) also gets installed. NPM is included in the installation as it includes many libraries that are used in web applications like React. So let’s verify if it's installed using this command in cmd: npm --version

npm-version

That’s all we need to do for a successful Node.js installation on a Windows system! If you're a Windows user, you can skip the next section and jump straight to the section in which we'll create a basic Node.js server to verify if everything works as expected.

Node.js Installation on Ubuntu

Here, we'll carry out Node.js installation on the Ubuntu system. 

Steps to Install on Ubuntu:

1. First, add the Node.js PPA to our system to install Node.js on Ubuntu:

sudo apt-get install curl

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

ubuntu-plat

2. Now run the below command to install Node using apt-get. This will also install NPM with Node.js:

ubuntu-platform

sudo apt-get install nodejs

3. Verify that Node.js and NPM are properly installed, by running this command:

node --version

npm --version

npm-version-2

Now that we’ve completed the installation of Node.js on both Windows and Ubuntu Operating Systems, let’s create a simple Node.js web server.

Full Stack Web Developer Course

To become an expert in MEAN StackView Course
Full Stack Web Developer Course

Creating a Simple Node.js Server

In this section, we'll create a simple Node.js web server. For this, we'll need a text editor, preferably VS Code or Atom. The code to create the server is as below:

var http = require('http');

http.createServer(function (req, res) {

  res.writeHead(200, {'Content-Type': 'text/plain'});

  res.end('Hey! You have successfully created a web server!!\n');

}).listen(3000, "127.0.0.1");

console.log('Server running at http://127.0.0.1:3000/');

Code explanation:

  • We declare a variable http that imports and contains the http module, which is required to interact with the web
  • HTTP module has a method called createServer that creates a server using a function with parameters req (request) and res (response)
  • We use the res (response) parameter to send a string to the web page
  • After that, we set the server to listen at port: 3000 and URL: “127.0.0.1”
  • We use the console.log method to log the output of the program in the cmd or terminal. If the program works fine, this method displays the string enclosed in the brackets
  • Finally, we save the file as server.js

We can now start the Node.js server that we just created using the command:

node server.js

Note: VS Code has a built-in terminal so you can run this command there.

vs-code

Since we get the String that we defined within the brackets of console.log method, we can see that Node.js server is now running and working as expected.

We can also check the response on the web page by going to the defined URL and port.

web-server

Since this also works absolutely fine, we can conclude that we’ve successfully installed Node.js in our system. 

Now the next logical step would be to start learning more about Node.js and eventually gain some hands-on knowledge about this very popular server-side platform.

Check out the video tutorial below to understand clearly the Node.js installation on Windows 10 and Ubuntu -

Learn for Free! Get access to our library of over 2000 learning videos. What are you waiting for?

”Get

Get Ahead of the Curve and Master Node.js Today

Now that you’ve learned about Node.js installation on Windows and Ubuntu, you may be wondering how you can obtain the skills necessary to take advantage of its rising popularity. 

Fortunately, there are some great options for learning this exciting and practical skill set at your own pace. Simplilearn’s Node.js Certification Training will give you a great foundation in this popular platform, combining live, instructor-led training, self-paced tutorials, and hands-on projects to help you become career-ready upon completion. Get started today to seize your future! 

About the Author

Taha SufiyanTaha Sufiyan

Taha is a Research Analyst at Simplilearn. He is passionate about building great user interfaces and keeps himself updated on the world of Artificial Intelligence. Taha is also interested in gaming and photography.

View More
  • Disclaimer
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, and OPM3 are registered marks of the Project Management Institute, Inc.