<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>KB Highlight Archives - ServerStadium</title>
	<atom:link href="https://serverstadium.com/knowledge-base/tag/kb-highlight/feed/" rel="self" type="application/rss+xml" />
	<link>https://serverstadium.com/knowledge-base/tag/kb-highlight/</link>
	<description>Public Cloud Solution by ServerStadium</description>
	<lastBuildDate>Thu, 27 Apr 2023 09:33:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.4</generator>

<image>
	<url>https://serverstadium.com/wp-content/uploads/2023/04/cropped-favicon-1-32x32.png</url>
	<title>KB Highlight Archives - ServerStadium</title>
	<link>https://serverstadium.com/knowledge-base/tag/kb-highlight/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to Install Node.js and Launch Your First Node App</title>
		<link>https://serverstadium.com/knowledge-base/how-to-install-node-js-and-launch-your-first-node-app/</link>
		
		<dc:creator><![CDATA[Brian K]]></dc:creator>
		<pubDate>Thu, 15 Apr 2021 03:42:50 +0000</pubDate>
				<guid isPermaLink="false">https://cloudraya.com/knowledge-base/?p=718</guid>

					<description><![CDATA[<p>The popularity of Node.js has increased recently, which makes &#8216;how to install node.js&#8217; a hot topic around the internet. But let&#8217;s discuss what Node.js is. Node.js is a server-side Javascript that makes dev can write the front-end and back-end of web applications in Javascript more easily and efficiently. Node.js is an open-source application under MIT&#8230;</p>
<p>The post <a href="https://serverstadium.com/knowledge-base/how-to-install-node-js-and-launch-your-first-node-app/">How to Install Node.js and Launch Your First Node App</a> appeared first on <a href="https://serverstadium.com">ServerStadium</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">The popularity of Node.js has increased recently, which makes &#8216;how to install node.js&#8217; a hot topic around the internet. But let&#8217;s discuss what Node.js is.<br /><br />Node.js is a server-side Javascript that makes dev can write the front-end and back-end of web applications in Javascript more easily and efficiently. Node.js is an open-source application under MIT License.<br /><br />This tutorial will teach us how to install node.js using the Ubuntu repository, PPA, or NVM. <br />And we will learn how to launch your simple app using node.js.</p>



<ol class="wp-block-list" type="1">
<li>Using Ubuntu repository. We will install using stable nodejs with command apt</li>
<li>Install nodejs using PPA (Personal Package Archive) repository.</li>
<li>Use and install multiple nodejs using NVM (NodeJS Version Manager).</li>
</ol>



<h2 class="has-vivid-cyan-blue-color has-text-color wp-block-heading">Install Node.js using Ubuntu Repository</h2>



<p class="wp-block-paragraph">Please ssh your server on Cloudraya and make sure you have created a security profile to allow accessing your server.</p>



<p class="wp-block-paragraph">After you login into your server, run the command below:</p>



<pre class="wp-block-preformatted"># apt update</pre>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="663" height="186" class="wp-image-743" src="https://serverstadium.com/wp-content/uploads/2021/01/image-6.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2021/01/image-6.png 663w, https://serverstadium.com/wp-content/uploads/2021/01/image-6-300x84.png 300w" sizes="(max-width: 663px) 100vw, 663px" /></figure>



<pre class="wp-block-preformatted"># apt install nodejs</pre>



<figure class="wp-block-image size-large"><img decoding="async" width="556" height="239" class="wp-image-745" src="https://serverstadium.com/wp-content/uploads/2021/01/image-8.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2021/01/image-8.png 556w, https://serverstadium.com/wp-content/uploads/2021/01/image-8-300x129.png 300w" sizes="(max-width: 556px) 100vw, 556px" /></figure>



<p class="wp-block-paragraph">Run the command below to find nodejs version:</p>



<pre class="wp-block-preformatted"># nodejs -v</pre>



<figure class="wp-block-image size-large"><img decoding="async" width="269" height="35" class="wp-image-746" src="https://serverstadium.com/wp-content/uploads/2021/01/image-9.png" alt="" /></figure>



<p class="wp-block-paragraph">If you want to find some module or package of nodejs, we can use NPM (NodeJS Package Manager). You can install it using the command :</p>



<pre class="wp-block-preformatted">#apt install npm</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="615" height="47" class="wp-image-748" src="https://serverstadium.com/wp-content/uploads/2021/01/image-11.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2021/01/image-11.png 615w, https://serverstadium.com/wp-content/uploads/2021/01/image-11-300x23.png 300w" sizes="(max-width: 615px) 100vw, 615px" /></figure>



<pre class="wp-block-preformatted"># npm -v</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="257" height="30" class="wp-image-750" src="https://serverstadium.com/wp-content/uploads/2021/01/image-13.png" alt="" /></figure>



<p class="wp-block-paragraph">Now your server is ready to use nodejs.</p>



<h2 class="has-vivid-cyan-blue-color has-text-color wp-block-heading">Install Node.js Using PPA (Personal Package Archive) Repository</h2>



<p class="wp-block-paragraph">If we want to use nodejs with the latest version, we can use nodejs using PPA Repository that is maintained by NodeSource.</p>



<p class="wp-block-paragraph">We can find version nodejs on <a href="https://github.com/nodesource/distributions">https://github.com/nodesource/distributions</a>.<br />Run the command below to install nodejs v.12.</p>



<pre class="wp-block-preformatted"># curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="659" height="104" class="wp-image-751" src="https://serverstadium.com/wp-content/uploads/2021/01/image-14.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2021/01/image-14.png 659w, https://serverstadium.com/wp-content/uploads/2021/01/image-14-300x47.png 300w" sizes="(max-width: 659px) 100vw, 659px" /></figure>



<p class="wp-block-paragraph">If we use nodejs from PPA, npm is automatically installed on your server.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="284" height="62" class="wp-image-753" src="https://serverstadium.com/wp-content/uploads/2021/01/image-16.png" alt="" /></figure>



<p class="wp-block-paragraph">&nbsp;</p>



<h2 class="has-vivid-cyan-blue-color has-text-color wp-block-heading">Install Node.js Using NVM (NodeJS Version Manager)</h2>



<p class="wp-block-paragraph">Nodejs allow us to install multiple nodejs versions on the server.<br />We recommend you use nodejs with NodeJs Version Manager (NVM). After we install nodejs using NVM, we can change the default nodejs version if we install multiple nodejs on the server.</p>



<p class="wp-block-paragraph">Below is how to install nodejs using NVM:</p>



<pre class="wp-block-preformatted"># apt install build-essential libssl-dev</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="528" height="212" class="wp-image-754" src="https://serverstadium.com/wp-content/uploads/2021/01/image-17.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2021/01/image-17.png 528w, https://serverstadium.com/wp-content/uploads/2021/01/image-17-300x120.png 300w" sizes="(max-width: 528px) 100vw, 528px" /></figure>



<pre class="wp-block-preformatted"># curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="740" height="299" class="wp-image-755" src="https://serverstadium.com/wp-content/uploads/2021/01/image-18.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2021/01/image-18.png 740w, https://serverstadium.com/wp-content/uploads/2021/01/image-18-300x121.png 300w" sizes="(max-width: 740px) 100vw, 740px" /></figure>



<p class="wp-block-paragraph">After the installation is completed, please allow NVM to run on bash profile user .</p>



<pre class="wp-block-preformatted"># source ~/.profile</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="344" height="40" class="wp-image-756" src="https://serverstadium.com/wp-content/uploads/2021/01/image-19.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2021/01/image-19.png 344w, https://serverstadium.com/wp-content/uploads/2021/01/image-19-300x35.png 300w" sizes="(max-width: 344px) 100vw, 344px" /></figure>



<p class="wp-block-paragraph">List the nodejs version using the command below:</p>



<pre class="wp-block-preformatted"># nvm ls-remote</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="421" height="331" class="wp-image-765" src="https://serverstadium.com/wp-content/uploads/2021/01/image-26.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2021/01/image-26.png 421w, https://serverstadium.com/wp-content/uploads/2021/01/image-26-300x236.png 300w" sizes="(max-width: 421px) 100vw, 421px" /></figure>



<p class="wp-block-paragraph">In this article, we will use nodejs LTS version with version 14.</p>



<pre class="wp-block-preformatted"># nvm install 14.15.3</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="616" height="125" class="wp-image-758" src="https://serverstadium.com/wp-content/uploads/2021/01/image-21.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2021/01/image-21.png 616w, https://serverstadium.com/wp-content/uploads/2021/01/image-21-300x61.png 300w" sizes="(max-width: 616px) 100vw, 616px" /></figure>



<p class="wp-block-paragraph">As we know, using NVM we can run multiple nodejs version on the server.<br />Now we will install nodejs version 8.</p>



<pre class="wp-block-preformatted"># nvm install 8.17.0</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="619" height="111" class="wp-image-759" src="https://serverstadium.com/wp-content/uploads/2021/01/image-22.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2021/01/image-22.png 619w, https://serverstadium.com/wp-content/uploads/2021/01/image-22-300x54.png 300w" sizes="(max-width: 619px) 100vw, 619px" /></figure>



<p class="wp-block-paragraph">Please run the command below to find nodejs version that is installed on the server.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="297" height="228" class="wp-image-762" src="https://serverstadium.com/wp-content/uploads/2021/01/image-24.png" alt="" /></figure>



<p class="wp-block-paragraph">We can see if the default nodejs on the server is nodejs version 14.<br />If we want to change the nodejs version 8, we can use the command below:</p>



<pre class="wp-block-preformatted"># nvm use 8</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="295" height="63" class="wp-image-763" src="https://serverstadium.com/wp-content/uploads/2021/01/image-25.png" alt="" /></figure>



<p class="wp-block-paragraph">&nbsp;</p>



<h2 class="has-vivid-cyan-blue-color has-text-color wp-block-heading"><strong>Launch </strong>Y<strong>our First Node App</strong></h2>



<p class="wp-block-paragraph">After we know how to install nodejs on the server using many different ways. Now we can learn how to launch your first node App on the server.</p>



<p class="wp-block-paragraph">Create folder nodejsapp and create a file as app.js</p>



<pre class="wp-block-preformatted">#mkdir nodejsapp
#cd nodejsapp
#nano app.js</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="363" height="46" class="wp-image-766" src="https://serverstadium.com/wp-content/uploads/2021/01/image-27.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2021/01/image-27.png 363w, https://serverstadium.com/wp-content/uploads/2021/01/image-27-300x38.png 300w" sizes="(max-width: 363px) 100vw, 363px" /></figure>



<p class="wp-block-paragraph">Append the code below on file app.js</p>



<pre class="wp-block-preformatted">console.log('This NodeJS Application in Cloudraya');</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="404" height="109" class="wp-image-767" src="https://serverstadium.com/wp-content/uploads/2021/01/image-28.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2021/01/image-28.png 404w, https://serverstadium.com/wp-content/uploads/2021/01/image-28-300x81.png 300w" sizes="(max-width: 404px) 100vw, 404px" /></figure>



<p class="wp-block-paragraph">Press Ctrl + x to save and quit from the editor.</p>



<p class="wp-block-paragraph">Run the command below to execute the code of app.js</p>



<pre class="wp-block-preformatted">#chmod +x app.js
#nodejs app.js or node app.js (if you use NVM)</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="394" height="48" class="wp-image-768" src="https://serverstadium.com/wp-content/uploads/2021/01/image-29.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2021/01/image-29.png 394w, https://serverstadium.com/wp-content/uploads/2021/01/image-29-300x37.png 300w" sizes="(max-width: 394px) 100vw, 394px" /></figure>



<h2 class="has-vivid-cyan-blue-color has-text-color wp-block-heading"><strong>Create Local Webserver</strong></h2>



<p class="wp-block-paragraph">Nodejs is a client-side server language which means we can run it without any webserver like nginx or apache. With nodejs we can create a local webserver on the server.<br /><br />First, we create a file server.js and append the code below on the file</p>



<pre class="wp-block-preformatted"># nano server.js</pre>



<pre class="wp-block-preformatted">var http = require('http');<br />var server = http.createServer(function (req, res) {<br />        res.writeHead(200,{'Content-Type': 'text/plain'});<br />        res.end('NodeJS App');<br />});<br />server.listen(5050);<br />console.log('Server is running at <a href="http://localhost:5050/">http://localhost:5050/</a>');</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="440" height="180" class="wp-image-769" src="https://serverstadium.com/wp-content/uploads/2021/01/image-30.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2021/01/image-30.png 440w, https://serverstadium.com/wp-content/uploads/2021/01/image-30-300x123.png 300w" sizes="(max-width: 440px) 100vw, 440px" /></figure>



<p class="wp-block-paragraph">Exit from the edit by press Ctrl + x to save and quit.</p>



<p class="wp-block-paragraph">The code we have appended on the file means making a server connection on port 5050. Please run the command below to run the local webserver</p>



<pre class="wp-block-preformatted"># nodejs server.js / node server.js (NVM)</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="382" height="76" class="wp-image-771" src="https://serverstadium.com/wp-content/uploads/2021/01/image-32.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2021/01/image-32.png 382w, https://serverstadium.com/wp-content/uploads/2021/01/image-32-300x60.png 300w" sizes="(max-width: 382px) 100vw, 382px" /></figure>



<p class="wp-block-paragraph">Now we can reach the node app via http://ip_address_server:5050 from any browser.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="502" height="283" class="wp-image-772" src="https://serverstadium.com/wp-content/uploads/2021/01/image-33.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2021/01/image-33.png 502w, https://serverstadium.com/wp-content/uploads/2021/01/image-33-300x169.png 300w" sizes="(max-width: 502px) 100vw, 502px" /></figure>



<p class="wp-block-paragraph">If you see the message above, you successfully launched the node app on the ServerStadium VM server.<br />Please submit your question to our Support if you need more assistance.</p>
<p>The post <a href="https://serverstadium.com/knowledge-base/how-to-install-node-js-and-launch-your-first-node-app/">How to Install Node.js and Launch Your First Node App</a> appeared first on <a href="https://serverstadium.com">ServerStadium</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
