A Beginner’s Guide to Node.JS

Harshit Katiyar
3 min readNov 1, 2023

--

So, you might have heard of JavaScript as of now. Javascript is a programming language that is used to make HTML pages dynamic. Node.js is something very close to it. In this guide, we’ll walk you through the basics of getting started with Node.js.

What is Node JS?

JavaScript gained a massive fan following from client-side scripting of websites, but it was not yet established as a proper programming language like Python, C, or Java. It was only limited to web browsers. So, to expand the usability of JS and to harness its full power on the server side, Node JS was developed. Node.js is a cross-platform, open-source server environment that can run on Windows, Linux, Unix, macOS, and more. It is built on the V8 JavaScript engine from Google and was created by Ryan Dahl in 2009. Please note that NodeJS is not a programming language in itself but only a server-side environment to run JavaScript. Many famous technologies, like React, Express, Vue, etc., are just the libraries of NodeJS. So, if you are going to start with any of these, you might as well start by learning NodeJS.

Installation

Let’s get NodeJS into our computers now.

  1. Download Node.js: Visit the official Node.js website (https://nodejs.org) and download the installer for your operating system. Node.js provides both a current and a LTS (long-term support) version. For most projects, it’s recommended to use the LTS version.
  2. Install Node.js: Run the downloaded installer and follow the on-screen instructions. This will install Node.js and its package manager, npm (Node Package Manager).
  3. Verify Installation: Open your command line or terminal and type the following commands to check if Node.js and npm were installed successfully:
node -v
npm -v

These commands should return the versions of Node.js and npm, respectively.

Your First NodeJS application

Now that you have Node.js installed, let’s create a simple “Hello, World!” application to get a feel for how Node.js works.

  1. Create a new directory: Open your command line or terminal and navigate to the directory where you want to create your Node.js project. You can create a new directory using the mkdir command:
  2. Create a JavaScript File: Inside your project directory, create a new JavaScript file. You can use any text editor or code editor to do this. Let’s name the fileapp.js.
  3. Write your code: Openapp.js and add the following code to display "Hello, World!" in the console:
console.log("Hello, World!");

4. Run Your Application: In the command line, navigate to your project directory and run the following command:

node app.js

You should see “Hello, World!” printed to the console.

What’s More?

Let us come back to the fact that JS was originally meant to be run on the client side. NodeJS has enabled devlopers to run JS on the server side, but how are two related? To answer that, NodeJS, just like any other languages has a lot of libraries (actually, much more than others). For example, ReactJS is a popular framework that helps in building the frontend much more efficiently than just writing plain HTML. We will talk about ReactJS and other great frameworks, that are nothing but libraries of NodeJS, in upcoming blogs.

Thanks for reading !

Author: Harshit Katiyar

--

--