<?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>part 1 Archives - SoftUni Global</title>
	<atom:link href="https://softuni.org/tag/part-1/feed/" rel="self" type="application/rss+xml" />
	<link>https://softuni.org/tag/part-1/</link>
	<description>Learn Programming and Start a Developer Job</description>
	<lastBuildDate>Thu, 09 Jun 2022 11:20:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://softuni.org/wp-content/uploads/2022/04/cropped-SoftUni-Global-Logo-Square-notext-32x32.png</url>
	<title>part 1 Archives - SoftUni Global</title>
	<link>https://softuni.org/tag/part-1/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>URL Shortener Project &#8211; Creating the App Structure [Part 1]</title>
		<link>https://softuni.org/project-tutorials/url-shortener-project-creating-the-app-structure/</link>
					<comments>https://softuni.org/project-tutorials/url-shortener-project-creating-the-app-structure/#respond</comments>
		
		<dc:creator><![CDATA[Aleksandar Peev]]></dc:creator>
		<pubDate>Thu, 10 Feb 2022 06:00:00 +0000</pubDate>
				<category><![CDATA[Step-by-Step Project Tutorials]]></category>
		<category><![CDATA[control systems]]></category>
		<category><![CDATA[express]]></category>
		<category><![CDATA[Express.js]]></category>
		<category><![CDATA[Kanban Boards]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[Node.js]]></category>
		<category><![CDATA[part 1]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[pug]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[software engineering]]></category>
		<category><![CDATA[step-by-step]]></category>
		<guid isPermaLink="false">https://softuni.org/?p=12280</guid>

					<description><![CDATA[<p>In this article of the Project Tutorial series, we will create a simple URL Shortener, using JavaScript, Node.js, Express.js and Pug</p>
<p>The post <a href="https://softuni.org/project-tutorials/url-shortener-project-creating-the-app-structure/">URL Shortener Project &#8211; Creating the App Structure [Part 1]</a> appeared first on <a href="https://softuni.org">SoftUni Global</a>.</p>
]]></description>
										<content:encoded><![CDATA[		<div data-elementor-type="wp-post" data-elementor-id="12280" class="elementor elementor-12280" data-elementor-post-type="post">
						<section class="elementor-section elementor-top-section elementor-element elementor-element-5d5405e elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="5d5405e" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-0d32134" data-id="0d32134" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-9216798 elementor-widget elementor-widget-text-editor" data-id="9216798" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>In this tutorial, we will create our <strong>URL Shortener</strong> using <strong>JavaScript</strong>. We will be using <strong>Expres.JS</strong> for creating the <strong>server-side web application</strong> and <strong>Pug</strong> as a <strong>template engine</strong>. This tutorial will be split into several parts, and in each part, we will further develop our project. In the end, we will have a fully working <strong>Multi Page Application</strong> (<strong>MPA</strong>).</p><p>After we <strong>initialize</strong> our project, we need to split our <strong>code logic</strong> into different folders. We create folders for:</p><ul><li><strong>data</strong></li><li><strong>controllers</strong></li><li><strong>views</strong></li><li><strong>public</strong></li></ul><p>In our main directory we have an <strong>index.js</strong> file that is automatically generated by <strong>repl.it</strong>. <span data-preserver-spaces="true">You don&#8217;t need to install manually any </span><strong><span data-preserver-spaces="true">libraries</span></strong><span data-preserver-spaces="true"> because they will be added </span><strong><span data-preserver-spaces="true">automatically</span></strong><span data-preserver-spaces="true"> when you start the project.</span></p><p>First, in our <strong>index.js</strong> we need to add the following code:</p><div id="malwarebytes-root"> </div>								</div>
				</div>
				<div class="elementor-element elementor-element-e972c9d elementor-widget elementor-widget-heading" data-id="e972c9d" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
					<h2 class="elementor-heading-title elementor-size-default">index.js</h2>				</div>
				</div>
				<div class="elementor-element elementor-element-2dd9888 elementor-widget elementor-widget-code-highlight" data-id="2dd9888" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-javascript line-numbers">
				<code readonly="true" class="language-javascript">
					<xmp>const express = require('express');
const app = express();
app.use(express.static('public'))
app.set('view engine', 'pug');

const data = require("./data/app-data");
data.seedSampleData();

const mvcController = require(
  "./controllers/mvc-controller");
mvcController.setup(app, data);

let port = process.argv[2];
if (!port) port = process.env['PORT'];
if (!port) port = 8080;

app.listen(port, () => {
  console.log(`App started. Listening at http://localhost:${port}`);
})
.on('error', function(err) {
  if (err.errno === 'EADDRINUSE')
    console.error(`Port ${port} busy.`);
  else 
    throw err;
});</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-dc9cfa9 elementor-widget elementor-widget-text-editor" data-id="dc9cfa9" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<ul><li><span data-preserver-spaces="true">In the first row, we </span><strong><span data-preserver-spaces="true">import</span></strong><span data-preserver-spaces="true"> the <strong>E</strong></span><strong><span data-preserver-spaces="true">xpressJS</span></strong><span data-preserver-spaces="true"> </span><strong><span data-preserver-spaces="true">node module</span></strong><span data-preserver-spaces="true">. Then we bind it to a </span><strong><span data-preserver-spaces="true">constant</span></strong><span data-preserver-spaces="true"> and use it to make </span><strong><span data-preserver-spaces="true">static</span></strong><span data-preserver-spaces="true"> our public folder. Doing this will allow us to use the <strong>public</strong> folder from any part of our application.</span></li><li><span data-preserver-spaces="true">We will also set our </span><strong><span data-preserver-spaces="true">view engine</span></strong><span data-preserver-spaces="true"> to </span><strong><span data-preserver-spaces="true">pug</span></strong><span data-preserver-spaces="true">. This will render all <strong>.pug</strong> files we set as <strong>views</strong>.</span></li><li><span data-preserver-spaces="true">We define constant named <strong>data</strong> and invoke the function. <strong>seedSampleData()</strong> inside it. We will create them later. Every time our project is started this function will be <strong>initialized</strong>.</span></li><li><span data-preserver-spaces="true">Our next task is to tell the index.js that our <strong>MVC-controller</strong> exists and set up it.</span></li><li><span data-preserver-spaces="true">We set our virtual port for repl.it to <strong>8080</strong>, and tell the program to listen to this <strong>port</strong>.</span></li><li><span data-preserver-spaces="true">If there is an <strong>error</strong>, it will be automatically <strong>displayed</strong> on the server&#8217;s console.</span></li></ul><div id="malwarebytes-root"></div>								</div>
				</div>
				<div class="elementor-element elementor-element-1ddcbde elementor-widget elementor-widget-heading" data-id="1ddcbde" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
					<h2 class="elementor-heading-title elementor-size-default">app-data.js</h2>				</div>
				</div>
				<div class="elementor-element elementor-element-8747339 elementor-widget elementor-widget-code-highlight" data-id="8747339" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-javascript line-numbers">
				<code readonly="true" class="language-javascript">
					<xmp>let urls = [];

function seedSampleData() {
  urls.length = 0; // cleanup
  urls.push({
    url: "https://softuni.org",
    shortCode: "su",
    dateCreated: new Date("2022-02-19T16:41:56"),
    visits: 86
  });
  urls.push({
    url: "https://nakov.com",
    shortCode: "nak", 
    dateCreated: new Date("2022-02-17T14:41:33"), 
    visits: 160
  });
}

module.exports = {
  urls,
  seedSampleData
};</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-4c6a3fa elementor-widget elementor-widget-text-editor" data-id="4c6a3fa" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<ul><li>In our <strong>data</strong> folder we create an <strong>app-data.js</strong> file. In it is we create our <strong>seed</strong> of <strong>data</strong>. We add an <strong>empty array</strong> that we fill with the <strong>seedSampleData()</strong> function.</li><li>In our function we have 2 different <strong>objects {}</strong> that we push into the <strong>urls</strong> array.</li><li>This is a <strong>temporary solution</strong> and in our next parts will be changed with a <strong>real database</strong>.</li></ul><div id="malwarebytes-root"></div>								</div>
				</div>
				<div class="elementor-element elementor-element-34726c4 elementor-widget elementor-widget-heading" data-id="34726c4" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
					<h2 class="elementor-heading-title elementor-size-default">mvc-controller.js</h2>				</div>
				</div>
				<div class="elementor-element elementor-element-4054f70 elementor-widget elementor-widget-code-highlight" data-id="4054f70" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-javascript line-numbers">
				<code readonly="true" class="language-javascript">
					<xmp>function setup(app, data) {
  app.get('/', function(req, res) {
    let visitors = 0;
    for (const url of data.urls) {
      console.log(url);
      visitors += url.visits;
    }
    let model = { urls: data.urls, visitors };
    res.render('home', model);
  });
}

module.exports = { setup };</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-a842882 elementor-widget elementor-widget-text-editor" data-id="a842882" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<ul><li><span data-preserver-spaces="true">Inside our <strong>controller</strong> folder we create the  <strong>mvc-controller.js</strong> file. Inside it, we add the function </span><strong><span data-preserver-spaces="true">setup()</span></strong><span data-preserver-spaces="true"> that receives the <strong>app</strong> and <strong>data</strong>. </span></li><li><span data-preserver-spaces="true">When our server recieves a <strong>GET</strong> request with a <strong>URL</strong> that equals<strong> &#8216;/&#8217;</strong>, it will <strong>invoke</strong> the following function.</span></li><li><span data-preserver-spaces="true"> We <strong>iterate</strong> over the <strong>collection of data</strong> and bind it into the <strong>model </strong>variable. </span></li><li><span data-preserver-spaces="true">Then, we <strong>render</strong> the following view with the <strong>data</strong> attached to it. </span></li><li><span data-preserver-spaces="true">After we are done, we <strong>export</strong> the function so that the <strong>index.js</strong> can run it correctly.</span></li></ul>								</div>
				</div>
				<div class="elementor-element elementor-element-3c39e95 elementor-widget elementor-widget-heading" data-id="3c39e95" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
					<h2 class="elementor-heading-title elementor-size-default">home.pug</h2>				</div>
				</div>
				<div class="elementor-element elementor-element-d245384 elementor-widget elementor-widget-code-highlight" data-id="d245384" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-javascript line-numbers">
				<code readonly="true" class="language-javascript">
					<xmp>h1 URL Shortener
ul
  li Short URLs: <b>#{urls.length}</b>
  li URL visitors: <b>#{visitors}</b>    </xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-b1c3462 elementor-widget elementor-widget-text-editor" data-id="b1c3462" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<ul><li><span data-preserver-spaces="true">Finally, we create our <strong>home.pug</strong> view inside the <strong>views</strong> folder. That is the html <strong>page</strong> that will load when the user goes to the </span>&#8216;/&#8217; <span data-preserver-spaces="true"><strong>URL, that we </strong>defined in our controller.</span></li><li><span data-preserver-spaces="true">We have an <strong>unordered list( ul )</strong>, in which we have two <strong>rows( li )</strong>. The first is for the count of our <strong>URLs</strong>, and the next is the total sum of all visitors summed from all<strong> 2 records</strong>.</span></li><li><span data-preserver-spaces="true">If we want to print the data <strong>bound</strong> to the variable </span><strong><span data-preserver-spaces="true">visitors</span></strong><span data-preserver-spaces="true">, we must add hashtag <strong>#</strong> and braces<strong> { }</strong> around it so that our compiler knows that this isn&#8217;t a regular <strong>HTML</strong> text.</span></li></ul><div id="malwarebytes-root"></div>								</div>
				</div>
				<div class="elementor-element elementor-element-74febac elementor-widget elementor-widget-text-editor" data-id="74febac" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p><img fetchpriority="high" decoding="async" class=" wp-image-12324 aligncenter" src="https://softuni.org/wp-content/uploads/2022/02/url-first-part-final-look-300x157.png" alt="url-first-part-final-look" width="332" height="174" srcset="https://softuni.org/wp-content/uploads/2022/02/url-first-part-final-look-300x157.png 300w, https://softuni.org/wp-content/uploads/2022/02/url-first-part-final-look.png 469w" sizes="(max-width: 332px) 100vw, 332px" />After completing all the steps you will have a simple working <strong>Multi Page Application</strong>. If you start your project, you will see that everything that we have done is working correctly. We are using the <strong>MVC architecture</strong>, and we have split the project into different folders and functions for better understanding. This way  you can clearly see where each part is located. Keep up with our parts and see how our project grows more.</p><div id="malwarebytes-root"></div>								</div>
				</div>
				<div class="elementor-element elementor-element-88292b4 elementor-widget elementor-widget-video" data-id="88292b4" data-element_type="widget" data-settings="{&quot;youtube_url&quot;:&quot;https:\/\/youtu.be\/P7-tvKIOwVs&quot;,&quot;video_type&quot;:&quot;youtube&quot;,&quot;controls&quot;:&quot;yes&quot;}" data-widget_type="video.default">
				<div class="elementor-widget-container">
							<div class="elementor-wrapper elementor-open-inline">
			<div class="elementor-video"></div>		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-edfdd22 elementor-widget elementor-widget-text-editor" data-id="edfdd22" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<h2>Lesson Topics</h2><div><div><div>In this tutorial we cover the following topics:</div></div><ul><li><strong>URL Shortener: App Walkthrough</strong></li><li><strong>Project Structure</strong></li><li><strong>Creating the App Structure</strong></li></ul></div>								</div>
				</div>
				<div class="elementor-element elementor-element-9fe4d6c elementor-widget elementor-widget-text-editor" data-id="9fe4d6c" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p style="text-align: left;">Remember that <strong>coding is a skill</strong>, which should be practiced. To learn to code, you should <strong>write code</strong> every day for a long time. Watching tutorials is not enough. <strong>You should code! </strong></p><p style="text-align: left;">We would love to hear from you, so leave a comment below saying what topics you would like to see next.</p><p style="text-align: left;">Register now and take your <strong>free resources</strong> right away! Become a member of the <strong>SoftUni Global Community </strong>and communicate with other <strong>students</strong> and <strong>mentors </strong>and get help for <strong>FREE</strong>.</p><p>After registering, you will get access to thе<strong> project code.</strong></p>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-187b057 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="187b057" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-a666564" data-id="a666564" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
							</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-a0aff0b elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="a0aff0b" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-48c6c18" data-id="48c6c18" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-1495bc9 elementor-align-center elementor-widget elementor-widget-button" data-id="1495bc9" data-element_type="widget" data-widget_type="button.default">
				<div class="elementor-widget-container">
									<div class="elementor-button-wrapper">
					<a class="elementor-button elementor-button-link elementor-size-xl" href="https://replit.com/@nakov/URLShortener-Part-1?v=1">
						<span class="elementor-button-content-wrapper">
									<span class="elementor-button-text">Source code Part 1</span>
					</span>
					</a>
				</div>
								</div>
				</div>
				<div class="elementor-element elementor-element-f972417 elementor-widget elementor-widget-heading" data-id="f972417" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
					<h2 class="elementor-heading-title elementor-size-default">Lesson Slides</h2>				</div>
				</div>
				<div class="elementor-element elementor-element-37e6760 elementor-widget elementor-widget-pdfjs_viewer" data-id="37e6760" data-element_type="widget" data-widget_type="pdfjs_viewer.default">
				<div class="elementor-widget-container">
					<iframe src="https://softuni.org/wp-content/plugins/pdf-viewer-for-elementor/assets/pdfjs/web/viewer.html?file=https://softuni.org/wp-content/uploads/2022/02/ShortURL-Project-Tutorial-Part-1-App-Structure.pdf&amp;embedded=true" style="display: block; margin-left: auto; margin-right: auto; width: 100%; height: 800px;" frameborder="1" marginheight="0px" marginwidth="0px" allowfullscreen></iframe>				</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				</div>
		<p>The post <a href="https://softuni.org/project-tutorials/url-shortener-project-creating-the-app-structure/">URL Shortener Project &#8211; Creating the App Structure [Part 1]</a> appeared first on <a href="https://softuni.org">SoftUni Global</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://softuni.org/project-tutorials/url-shortener-project-creating-the-app-structure/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)

Served from: softuni.org @ 2026-06-09 18:27:50 by W3 Total Cache
-->