How to Setup Node.js Server on your Local Windows or Linux Machine

3
143
Nodejs server setup

Hello, friends how are you today !!! so today I just thought that there should be something other than hacking šŸ˜€ šŸ˜€ so this article is for all those programming lovers and also you can use this tutorial to setup your own API testing server. In this articles, we are going to learnĀ How to Setup Node.js Server on your Local Windows or Linux Machine so without further due let us get started.

 

What is Node.js?

Let’s dive into the boring stuff:

Node.js is a JavaScript platform built on Chrome’s JavaScript runtime for easily building fast and salable network applications.Ā Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

Mostly is being used to develop API’s for applications and it is a server-side platform, Node.js is an open source, a cross-platform runtime environment for developing server-side and network applications.

There are many libraries written in Node.js for support and functionality for developing Node.js applications.

JavaScript is becoming a go-to language for web developers. Front-end developers use it to add animations and user interface enhancements, add interactivity, and talk to the back-end server to get information using AJAX.Ā  Developers who work on the server-side are also shifting to JavaScript because of the efficiencies and speed offered by JavaScriptā€™s event-driven, non-blocking nature.

Node.js is also used for developing desktop applications and for deploying tools that make developing websites simpler and easier. For example, by installing Node.jsĀ® on your desktop machine, you can quickly convert CoffeeScript to JavaScript, SASS to CSS, and shrink the size of your HTML, JavaScript, and graphics files. Using NPM ā€” a tool that makes installing and managing Node modules ā€” itā€™s quite easy to add many useful tools to your web development toolkit.

What should you know before getting into it?

You should know that Node is not an application that you can pin into the taskbar and use it like MS Word or Photoshop. It is a command line application and you should know the basics to use Command line.

Setup Node js Server local Windows / Linux machine:-

Installation on Windows:-

Installing Node.js on windows is pretty straightforward as Node.js provides an installer for windows on their website.

Steps:-

  1. Download the windows installer from the Node.js website.
  2. Run the installer (the .msiĀ installer that you downloaded from the website.)
  3. Follow the prompts in the installer (Accept the license agreement with default installation settings.)Node.js Installer
  4. Restart your computer. You wonā€™t be able to run Node.jsĀ® until you restart your computer.

Testing it!!

To make sure that the NPM and Node have been installed successfully on your system you can check this just by typing commands in the command prompt.

  • Test Node. To see if Node is installed, open Windows Command Prompt, Powershell, and type.node -v This should print the version number, something likeĀ v8.9.1 .nodeversion
  • Test NPM. And to test NPM just type innpm -v the Command Prompt or Powershell and it will show you something like this.5.5.1npm version
  • Create a test file and run it. A simple way to test that node.js works is to create a JavaScript file: name it,hello.js and just add the code.console.log('Everything Up and running'); To run the code simply open your command line program, navigate to the folder where you save the file and type.node hello.js This will start Node and run the code in the filehello.js. You should see the output.Everything Up and runninghellojs test file

And if your are still having this issue here is the video that you can follow:-

How to Update:-

Just got to the Node website and download the latest version and install it.

How to uninstall:-

Simply go to your control panel and uninstall the Node.js package.

Also Read:Ā Top Kali Linux Tools Every Hacker Should Know About and Learn

Installation On Linux:-

The best operating system out there for developers so let’s get started how to install Node.js on Linux. Ubuntu contains version of Node.js in its default repositories that can be easily used.

In order to get it installed, we just need to use the apt package manager on Debian Linux distros. First get updates form the servers and refresh local package index.

sudo apt-get update

sudo apt-get install nodejs

If the version of Nodejs in the repositories suits your needs, this is all that you need to do to get set up with Node.js. and in most cases you will also install npm which is Node.js package manager typing:

sudo apt-get install npm

This will allow you to easily install modules and packages to use with Node.js.

Because of a conflict with another package, the executable from the Ubuntu repositories is calledĀ nodejsĀ instead ofĀ node. Keep this in mind as you are running software.

Below, we’ll discuss some more flexible methods of installation.

Install Using PPA:-

An alternative way that you can you to install Node.js and you can get the more recent version of Node.js and its added in your PPA (Personal package archive).

First, you need to install the PPA in order to get access to its contents. This depends on the version you wish to install.

For the most recent LTS (8.x version) use:

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

For the currently active version release (9.x version) use:

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

After you have added this to your PPA you just need to run this command to install it.

sudo apt-get install nodejs

As this packagenodejs contains the nodejs binary and npm so we don’t have to install it separately. But in order to for npm to work properly, we will have to install the required libraries on the system.

sudo apt-get install build-essential

How To Install Using NVM

An alternative to installing Node.js throughĀ aptĀ is to use a specially designed tool calledĀ nvm, which stands for “Node.js version manager”.

Using nvm, you can install multiple, self-contained versions of Node.js which will allow you to control your environment easier.

First, we need some packages to be installed on the system.

sudo apt-get update
sudo apt-get install build-essential libssl-dev

Now we want to run the nvm installation file so we have to download it fromĀ GitHub:

curl https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | sh

This will download the script and run it. It will install the software into a subdirectory of your home directory atĀ ~/.nvm. It will also add the necessary lines to yourĀ ~/.profileĀ file to use the file.

To gain access to the nvm functionality, you’ll need to log out and log back in again, or you can source theĀ ~/.profileĀ file so that your current session knows about the changes:

source ~/.profile

Now that you have nvm installed, you can install isolated Node.js versions.

To find out the versions of Node.js that are available for installation, you can type:

nvm ls-remote
. . .
v0.11.6
v0.11.7
v0.11.8
v0.11.9
v0.11.10
v0.11.11
v0.11.12
v0.11.13

As you can see, the newest version at the time of this writing is v0.11.13. You can install that by typing:

nvm install 0.11.13

Usually, nvm will switch to use the most recently installed version. You can explicitly tell nvm to use the version we just downloaded by typing:

nvm use 0.11.13

When you install Node.js using nvm, the executable is calledĀ node. You can see the version currently being used by the shell by typing:

node -v
v.0.11.13

If you have multiple Node.js versions, you can see what is installed by typing:

nvm ls

If you wish to default one of the versions, you can type:

nvm alias default 0.11.13

This version will be automatically selected when a new session spawns. You can also reference it by the alias like this:

nvm use default

Each version of Node.js will keep track of its own packages and hasĀ npmĀ available to manage these.

You can haveĀ npmĀ install packages to the Node.js project’sĀ ./node_modulesdirectory by using the normal format:

npm install express

If you’d like to install it globally (available to the other projects using the same Node.js version), you can add theĀ -gĀ flag:

npm install -g express

This will install the package in:

~/.nvm/node_version/lib/node_modules/package_name

Installing globally will let you run the commands from the command line, but you’ll have to use link the package into your local sphere to require it from within a program:

npm link express

You can learn more about the options available to you with nvm by typing:

nvm help
Thats all and now you can get started and create new and intresting application using Node.js and learn new things.
SHARE
Previous articleComplete How to Guide for MSFvenom

Hello friends i am a Web Application Security Researcher and CEO of this site. I love to share my knowledge through this site and hope that i can help you.

  • Pingback: Node.js Weekly Update – November 24 | Webammer()

  • Amiram Korach

    Every dev person should use NVM only. It won’t require sudo in any npm install -g command. There is also an nvm-windows version which is not exactly the same thing but behaves almost the same.

    • Totally agree with you it really helps to keep all of your Node projects in their separate virtual environment.