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:
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.
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.
- Download the windows installer from the Node.js website.
- Run the installer (the .msi installer that you downloaded from the website.)
- Follow the prompts in the installer (Accept the license agreement with default installation settings.)
- Restart your computer. You won’t be able to run Node.js® until you restart your computer.
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 -vThis should print the version number, something like
- Test NPM. And to test NPM just type in
npm -vthe Command Prompt or Powershell and it will show you something like this.
hello.jsand 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.jsThis will start Node and run the code in the file
hello.js. You should see the output.
Everything Up and running
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.
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 package
nodejs 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:
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:
. . . 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:
If you have multiple Node.js versions, you can see what is installed by typing:
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
npm install -g express
This will install the package in:
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: