<?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>VM Instances Archives - ServerStadium</title>
	<atom:link href="https://serverstadium.com/knowledge-base/tag/vm-instances/feed/" rel="self" type="application/rss+xml" />
	<link>https://serverstadium.com/knowledge-base/tag/vm-instances/</link>
	<description>Public Cloud Solution by ServerStadium</description>
	<lastBuildDate>Tue, 30 May 2023 21:16:55 +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>VM Instances Archives - ServerStadium</title>
	<link>https://serverstadium.com/knowledge-base/tag/vm-instances/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Building Your First Application with the MEAN Stack on ServerStadium VM Instances</title>
		<link>https://serverstadium.com/knowledge-base/building-mean-stack-app-serverstadium-vm-instances/</link>
		
		<dc:creator><![CDATA[Brian K]]></dc:creator>
		<pubDate>Tue, 30 May 2023 21:16:55 +0000</pubDate>
				<guid isPermaLink="false">https://serverstadium.com/?post_type=epkb_post_type_1&#038;p=11690</guid>

					<description><![CDATA[<p>Once you have the MEAN Stack set up on your ServerStadium VM instance, you can start building your first application. This guide will walk you through the process of creating a simple application. Before we dive in, make sure you&#8217;ve followed our previous guide on Setting up a MEAN Stack on ServerStadium VM Instances. Step&#8230;</p>
<p>The post <a href="https://serverstadium.com/knowledge-base/building-mean-stack-app-serverstadium-vm-instances/">Building Your First Application with the MEAN Stack on ServerStadium VM Instances</a> appeared first on <a href="https://serverstadium.com">ServerStadium</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Once you have the MEAN Stack set up on your ServerStadium VM instance, you can start building your first application. This guide will walk you through the process of creating a simple application.</p>
<p>Before we dive in, make sure you&#8217;ve followed our previous guide on <a href="https://serverstadium.com/knowledge-base/mean-stack-setup-serverstadium-vm-instances" target="_new" rel="noopener">Setting up a MEAN Stack on ServerStadium VM Instances</a>.</p>
<h2>Step 1: Create an Express.js Server</h2>
<p>Start by creating a new directory for your project and navigating into it:</p>
<pre><code class="!whitespace-pre hljs language-bash"><span class="hljs-built_in">mkdir</span> mean-app
<span class="hljs-built_in">cd</span> mean-app
</code></pre>
<p>Initialize a new Node.js application:</p>
<div class="bg-black rounded-md mb-4">
<pre class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-bash">npm init -y
</code></pre>
</div>
<p>Install Express.js:</p>
<div class="bg-black rounded-md mb-4">
<pre class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-bash">npm install express
</code></pre>
</div>
<p>Create a new file named <code>server.js</code>:</p>
<div class="bg-black rounded-md mb-4">
<pre class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-bash"><span class="hljs-built_in">touch</span> server.js
</code></pre>
</div>
<p>Open <code>server.js</code> in your text editor and add the following code to create a basic Express.js server:</p>
<div class="bg-black rounded-md mb-4">
<pre class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-javascript"><span class="hljs-keyword">const</span> express = <span class="hljs-built_in">require</span>(<span class="hljs-string">'express'</span>);
<span class="hljs-keyword">const</span> app = <span class="hljs-title function_">express</span>();
<span class="hljs-keyword">const</span> port = <span class="hljs-number">3000</span>;

app.<span class="hljs-title function_">get</span>(<span class="hljs-string">'/'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
  res.<span class="hljs-title function_">send</span>(<span class="hljs-string">'Hello World!'</span>);
});

app.<span class="hljs-title function_">listen</span>(port, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Server is running at http://localhost:<span class="hljs-subst">${port}</span>`</span>);
});</code></pre>
<p>Run your server with <code>node server.js</code>. You should see &#8220;Server is running at http://localhost:3000&#8221; in your console. You can visit this URL in your browser to see your server in action.</p>
<h2>Step 2: Connect to MongoDB</h2>
<p>Install the MongoDB driver for Node.js:</p>
<div class="bg-black rounded-md mb-4">
<pre class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-bash">npm install mongodb
</code></pre>
</div>
<p>Update <code>server.js</code> to connect to your MongoDB database:</p>
<div class="bg-black rounded-md mb-4">
<pre class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-javascript"><span class="hljs-keyword">const</span> express = <span class="hljs-built_in">require</span>(<span class="hljs-string">'express'</span>);
<span class="hljs-keyword">const</span> mongodb = <span class="hljs-built_in">require</span>(<span class="hljs-string">'mongodb'</span>);
<span class="hljs-keyword">const</span> app = <span class="hljs-title function_">express</span>();
<span class="hljs-keyword">const</span> port = <span class="hljs-number">3000</span>;

mongodb.<span class="hljs-property">MongoClient</span>.<span class="hljs-title function_">connect</span>(<span class="hljs-string">'mongodb://localhost:27017'</span>, <span class="hljs-function">(<span class="hljs-params">err, client</span>) =&gt;</span> {
  <span class="hljs-keyword">if</span> (err) {
    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(err);
    <span class="hljs-keyword">return</span>;
  }

  <span class="hljs-keyword">const</span> db = client.<span class="hljs-title function_">db</span>(<span class="hljs-string">'mydb'</span>);

  app.<span class="hljs-title function_">get</span>(<span class="hljs-string">'/'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
    res.<span class="hljs-title function_">send</span>(<span class="hljs-string">'Connected to MongoDB!'</span>);
  });

  app.<span class="hljs-title function_">listen</span>(port, <span class="hljs-function">() =&gt;</span> {
    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Server is running at http://localhost:<span class="hljs-subst">${port}</span>`</span>);
  });
});
</code></pre>
</div>
<h2>Step 3: Create an Angular App</h2>
<p>Navigate to a different directory where you want to create your Angular app:</p>
<div class="bg-black rounded-md mb-4">
<pre class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-bash"><span class="hljs-built_in">cd</span> ..
ng new mean-angular-app
<span class="hljs-built_in">cd</span> mean-angular-app
</code></pre>
</div>
<p>Serve your Angular app:</p>
<div class="bg-black rounded-md mb-4">
<div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-bash">ng serve<br />
</code></div>
</div>
<p>You should see &#8220;Angular Live Development Server is listening on localhost:4200&#8221; in your console. You can visit this URL in your browser to see your Angular app.</p>
<h2>Step 4: Connect Angular to Express.js</h2>
<p>First, install the <code>http</code> package in your Angular app:</p>
<div class="bg-black rounded-md mb-4">
<pre class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-bash">npm install @angular/common/http</code></pre>
<p>Update the <code>app.component.ts</code> file in your Angular app to make a GET request to your Express.js server</p>
<div class="bg-black rounded-md mb-4">
<pre class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-typescript"><span class="hljs-keyword">import</span> { <span class="hljs-title class_">HttpClient</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/common/http'</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">AppComponent</span> {
  title = <span class="hljs-string">'mean-angular-app'</span>;
  message = <span class="hljs-string">''</span>;

  <span class="hljs-title function_">constructor</span>(<span class="hljs-params"><span class="hljs-keyword">private</span> http: HttpClient</span>) {
    <span class="hljs-variable language_">this</span>.<span class="hljs-property">http</span>.<span class="hljs-title function_">get</span>(<span class="hljs-string">'http://localhost:3000'</span>).<span class="hljs-title function_">subscribe</span>(<span class="hljs-function">(<span class="hljs-params">data: <span class="hljs-built_in">any</span></span>) =&gt;</span> {
      <span class="hljs-variable language_">this</span>.<span class="hljs-property">message</span> = data;
    });
  }
}
</code></pre>
</div>
<p>Update the <code>app.component.html</code> file in your Angular app to display the message from your Express.js server:</p>
<pre class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>{{ message }}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span></code></pre>
<h2>Conclusion</h2>
<p>Congratulations! You&#8217;ve just created your first MEAN Stack application on a ServerStadium VM instance. This guide only scratches the surface of what you can do with the MEAN Stack. To further your knowledge, explore our <a href="https://serverstadium.com/knowledge-base/" target="_new" rel="noopener">Knowledge Base</a> for more tutorials and guides.</p>
<p>Remember, our team at ServerStadium is always ready to assist you with your needs. Feel free to <a href="https://serverstadium.com/contact" target="_new" rel="noopener">reach out</a> to us if you have any questions or need further assistance.</p>
</div>
</div>
<p>The post <a href="https://serverstadium.com/knowledge-base/building-mean-stack-app-serverstadium-vm-instances/">Building Your First Application with the MEAN Stack on ServerStadium VM Instances</a> appeared first on <a href="https://serverstadium.com">ServerStadium</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
