This blog will show, how to setup Node.js and NPM on your managed hosting server. We are going to host in Linux server.
Before moving forward, please keep your SSH credentials in hand. We are going to use SSH
tool to install Node.js
and NPM
.
Prerequisites
- Your hosting account must have
SSH
(not jailshell) enabled. To check whichshell
your account is using, login yourSSH
account and type the following command:
1 2 |
zeptobook@domain [~]# echo $SHELL /bin/bash |
Node.js
currently only works on servers running CentOS 6 or CentOS 7. To check the version of CentOS on your server, log in to your account usingSSH
, and then type this command:
1 2 |
zeptobook@domain [~]# uname -r 3.10.0-714.10.2.lve1.5.19.7.el7.x86_64 |
If the output from this command contains el6 (for example, 2.6.32-531.17.1.lve1.2.60.el6.x86_64) or el7 (for example, 3.10.0-714.10.2.lve1.5.12.el7.x86_64) , then your server is running CentOS 6 or CentOS 7.
However, if you see el5h (for example, 2.6.32-531.23.3.lve1.2.66.el5h.x86_64), then your server is running CentOS 5 and does not support Node.js. Please contact your hosting provider.
Installing Node.js and NPM
- After your account meets the installation prerequisites, you can download and install
Node.js
andNPM
(the Node.js package manager). To do this, follow these steps:
1 2 |
zeptobook@domain [~]# cd ~ zeptobook@domain [~]# wget https://nodejs.org/dist/v10.5.0/node-v10.5.0-linux-x64.tar.xz |
This will save node.js package on your server directory.
1 2 3 4 |
zeptobook@domain [~]# ls access-logs@ node-v10.5.0-linux-x64.tar.xz public_html/ tmp/ etc/ perl5/ srbackups/ www@ mail/ public_ftp/ ssl/ |
- To extract the Node.js files, type this command:
1 |
zeptobook@domain [~]# tar xvf node-v10.5.0-linux-x64.tar.xz |
- To rename the extracted folder to the more convenient
nodejs
name, type this command:
1 |
zeptobook@domain [~]# mv node-v10.5.0-linux-x64 nodejs |
1 2 3 4 |
zeptoboo@az1-ss6 [~]# ls access-logs@ nodejs/ public_ftp/ ssl/ etc/ node-v10.5.0-linux-x64.tar.xz public_html/ tmp/ mail/ perl5/ srbackups/ www@ |
- To install the
node
andnpm
binaries, type these commands (may not be a required step in your setup):
1 2 3 4 |
zeptobook@domain [~]# mkdir ~/bin zeptobook@domain [~]# cp nodejs/bin/node ~/bin zeptobook@domain [~]# cd ~/bin zeptobook@domain [~/bin]# ln -s ../nodejs/lib/node_modules/npm/bin/npm-cli.js npm |
- After you run these commands,
Node.js
andNPM
are installed on your account. To verify this, type these following commands:
1 2 3 4 |
zeptobook@domain [~/bin]# node --version v10.5.0 zeptobook@domain [~/bin]# npm --version 6.1.0 |
The ~/bin directory is in your path by default, which means you can run node and npm from any directory in your account.
Creating your Node.js application on server
After successful installation of Node.js and NPM on your service, next step is create a node.js application. So, I have created a subdomain services.zeptobook.com
, and put the node.js app there.
Create a server.js
file on local, and upload it to the subdomain directory.
server.js
1 2 3 4 5 6 7 8 |
var http = require('http'); http .createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write('Hello Node.js Server @ A2 Shared Hosting!'); res.end(); }).listen(49500); |
Now, go to SSH terminal, and go to your subdomain directory, and run this command.
1 |
zeptobook@domain [~/services.zeptobook.com]# node server.js |
Now, go to the PostMan tool, and access your service url.
1 |
GET http://services.zeptobook.com:49500/ |
This is how, you can setup Node.js and NPM on your linux server.
Summary
In this blog, we learned about setting up Node.js and NPM on Linux hosting server.
Read more:
- Creating your first app in Angular 7
- Cool features of Generics in TypeScript
- Learn Functions In TypeScript
- Update Angular 6 to Angular 7 version
Pingback: Custom Directives in Angular 7 - ZeptoBook
Pingback: Fresh releases of Visual Studio 2017 for Mac and TypeScript 3.2 - ZeptoBook
Pingback: How to create Restful CRUD API with Node.js MongoDB and Express.js - ZeptoBook
Pingback: Running GraphQL Server Using Node.JS & Express on Linux Hosting Server - ZeptoBook