Shams Nahid
Shams Nahid's Blog

Shams Nahid's Blog

Get started with Node.js (Installation and Hello World Application)

Shams Nahid's photo
Shams Nahid

Published on Jul 5, 2019

2 min read

Welcome to Javascript world.

The popularity of javascript has brought dramatically changed in app development paradigm. And server-side development revolution started with the Node.js. According to the node.js official site, Node.js is

Asynchronous event driven JavaScript runtime, Node is designed to build scalable network applications.

Agenda

In this article, we

  1. Install Node.js in your system.

  2. Run a Hello world application in your application.

Installation

There are several ways to install node.js in your system.

  • Using the official Node.js site.

  • Using nvm (Recommended and we will discuss the procedure here in details)

NVM

nvm is a Node Version Manager, available for Linux and Mac. Also, there is a version available for windows user from separate developers.

Linux/Mac User

If you are a Linux or Mac user, stay with me. Windows user, please go to the next section.

Please install the curlif not installed.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

Or wget, the preinstalled download manager

In case your Linux distro does not ship with curl use default wget download manager.

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

Now set the environment variable and load nvm

export NVM_DIR="${XDG_CONFIG_HOME/:-$HOME/.}nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

Now, restart your terminal and update

source ~/.bashrc

So now, nvm must be installed in your system.

Windows User

Go to the download page and install your machine.

Verification

Linux/Mac user run the command

command -v nvm

This should output the nvm

Usage

To install the latest version of node, just run

nvm install node

To install a specific version of node

nvm install version

Replace version with your desired node version

Hello World

In this section, we will create a console app, hello world

Create a file in your machine named index.js

In your index.js file, write

console.log('Hello World!!!');

Go to terminal and run

node index.js

Voila!!, you just run your first node.js application.

Your terminal should output

Hello World!!!

NVM Misc

Get available node.js list By,

nvm ls-remote

Switch to the specific node.js version by,

nvm use version

NB: Before switch to a specific version, install that version nvm install version

Conclusion

Stay tuned and if there is a confusing term or something, make the response below. I will replay ASAP.

 
Share this