<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Xavier577</title>
    <description>The latest articles on DEV Community by Xavier577 (@xavier577).</description>
    <link>https://dev.to/xavier577</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F626299%2Fbfc63319-5239-4730-be35-72dd840b7eba.jpeg</url>
      <title>DEV Community: Xavier577</title>
      <link>https://dev.to/xavier577</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/xavier577"/>
    <language>en</language>
    <item>
      <title>Setting up a vanilla Typescript project the right way</title>
      <dc:creator>Xavier577</dc:creator>
      <pubDate>Mon, 04 Oct 2021 13:48:38 +0000</pubDate>
      <link>https://dev.to/xavier577/setting-up-a-vanilla-typescript-project-the-right-way-21ao</link>
      <guid>https://dev.to/xavier577/setting-up-a-vanilla-typescript-project-the-right-way-21ao</guid>
      <description>&lt;p&gt;Are you new learning typescript or you are an experienced typescript developer? chances are you have the urge to use it in any and every project rather than using plain javascript maybe because it gives you that sense of security. If by any chance you haven't heard about typescript or have heard of it but never tried it (which i doubt is possible lol) ,Typescript is superset of Javascript which means it is essentially javascript with more features. Typescript is optionally statically typed which means you have to option to write code which has type checking during compile time. I am not gonna talk to much about that here, this is &lt;a href="https://eslam-7ot.hashnode.dev/typescript-basics-types" rel="noopener noreferrer"&gt;eslam's article on typescript&lt;/a&gt; and also the offical &lt;a href="https://www.typescriptlang.org/" rel="noopener noreferrer"&gt;doc&lt;/a&gt; if you want to learn more about it.&lt;/p&gt; &lt;h1 id="a-problem-to-be-solved"&gt;A problem to be solved&lt;/h1&gt; &lt;p&gt; Typescript is awesome no doubt but sometimes using it with just plain html and css was hassle for me . Running the &lt;code&gt;tsc&lt;/code&gt; command every five minutes to see my changes was really annoying . I even tried &lt;code&gt;tsc --watch&lt;/code&gt;, this worked for a while but presented me with a problem, it would compile every typecript file i create into their separate javascript counterpart. And using custom modules became a problem. I began to wonder if there was a way to compile all my typescript code including modules into a single javascript bundle. I made my research and I discover there was a way.&lt;/p&gt; &lt;h1 id="the-solution"&gt;The solution&lt;/h1&gt; &lt;p&gt;After searching through google and eventually youtube, I realize that there weren't many articles or video to solve this problem, could it be that most people only use typescript in frameworks such as React or Angular and never use it with plain html or css? who knows. I eventually found a way thanks to &lt;a href="https://www.youtube.com/c/CodingEntrepreneurs" rel="noopener noreferrer"&gt;codingEnterpreneurs&lt;/a&gt; youtube channel. He did a variation of this in his youtube channel on his learn typescript playlist you can checkout his playlist &lt;a href="https://youtu.be/yRQlo6ApYLw?list=PLEsfXFp6DpzQMickZgPq0Pn2uQD77UXoi" rel="noopener noreferrer"&gt;here&lt;/a&gt;. Subscribe to his channel if you find his content interesting (I am not an affiliate or anything I just value good content, although I wish I were I wouldn't be broke all the time lol). With that said , this was one of the few solutions I found which is what inspired me to write this article. Without wasting any more time let's get to it!&lt;/p&gt; &lt;h1 id="getting-started-with-the-project"&gt;Getting started with the project&lt;/h1&gt; &lt;p&gt;Before we anything we need the following for this to work:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;nodejs&lt;/li&gt; &lt;li&gt;npm&lt;/li&gt; &lt;li&gt;git&lt;/li&gt; &lt;li&gt;typescript&lt;/li&gt; &lt;li&gt;webpack and webpack-cli&lt;/li&gt; &lt;li&gt;ts-loader&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;Now let's Go!&lt;/p&gt; &lt;p&gt;In your projects root directory:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;npm &lt;span class="hljs-keyword"&gt;init&lt;/span&gt; -y &lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt; &lt;p&gt;This will create a package.json file.&lt;/p&gt; &lt;/blockquote&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629664613455%2F8--rNO4jD.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629664613455%2F8--rNO4jD.png" alt="packagejson-created.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;initialize git with:&lt;/p&gt; &lt;pre&gt;&lt;code&gt; git &lt;span class="hljs-keyword"&gt;init&lt;/span&gt; &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;create .gitignore file (so we can ignore the node modules folder that will be created when we install our dependencies)&lt;/p&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629666629681%2FndIvL0evG.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629666629681%2FndIvL0evG.png" alt="gitignore-file-created.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;in the .gitignore file add:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;node_modules &lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Installing the required dependencies&lt;/h2&gt;
  &lt;p&gt;Install webpack and webpack-cli&lt;/p&gt; &lt;pre&gt;&lt;code&gt;&lt;span class="hljs-built_in"&gt;npm&lt;/span&gt; install webpack webpack-cli &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629666677965%2F9PpvNnEQS.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629666677965%2F9PpvNnEQS.png" alt="installing_webpack.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Install typescript and ts-loader&lt;/p&gt; &lt;pre&gt;&lt;code&gt;&lt;span class="hljs-built_in"&gt;npm&lt;/span&gt; install typescript ts-loader &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629666702101%2Fz8piEaP_-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629666702101%2Fz8piEaP_-.png" alt="installing_typescript.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;You should now see all our installed dependencies in the package.json file under the dependencies property&lt;/p&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629666716303%2FJNUZ01tlZ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629666716303%2FJNUZ01tlZ.png" alt="dependencies.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt; Now we will create two folders: &lt;/p&gt;
&lt;ul&gt; &lt;li&gt; public &lt;/li&gt; &lt;li&gt; src &lt;/li&gt; &lt;/ul&gt; &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629666735322%2FK0HrpGa_O.png" alt="create_public_and_src_folders.PNG"&gt;  &lt;p&gt; In public, we will create our index.html, static folder and our assets folder &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629666810439%2FncWPEVY5D.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629666810439%2FncWPEVY5D.png" alt="files_in_public.PNG"&gt;&lt;/a&gt; index.html is our html file (obviously lol) assets folder will contain files such as images,svgs, videos and so on static folder will contain two additional folders: &lt;/p&gt;
&lt;ul&gt; &lt;li&gt; css =&amp;gt; this would contain our styles &lt;/li&gt; &lt;li&gt; bundle =&amp;gt; this would be the destination of our compiled typescript code by webpack &lt;/li&gt; &lt;/ul&gt; &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629666833927%2FU25DMCIpvr.png" alt="files_in_static.PNG"&gt;  &lt;p&gt; In src, create index.ts files and tsconfig.json &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629666850732%2FNkv7L1Ldy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629666850732%2FNkv7L1Ldy.png" alt="files_in_src.PNG"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Add this to tsconfig.json:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;{ &lt;span class="hljs-attr"&gt;"compilerOptions"&lt;/span&gt;: { &lt;span class="hljs-attr"&gt;"target"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"es5"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"module"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"ESNEXT"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"rootDir"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"./"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"strict"&lt;/span&gt;: &lt;span class="hljs-literal"&gt;true&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"moduleResolution"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"node"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"allowSyntheticDefaultImports"&lt;/span&gt;: &lt;span class="hljs-literal"&gt;true&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"esModuleInterop"&lt;/span&gt;: &lt;span class="hljs-literal"&gt;true&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"skipLibCheck"&lt;/span&gt;: &lt;span class="hljs-literal"&gt;true&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"forceConsistentCasingInFileNames"&lt;/span&gt;: &lt;span class="hljs-literal"&gt;true&lt;/span&gt; } } &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the root directory, create webpack.config.js files and add this to the file:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;&lt;span class="hljs-keyword"&gt;const&lt;/span&gt; path = &lt;span class="hljs-built_in"&gt;require&lt;/span&gt;(&lt;span class="hljs-string"&gt;"path"&lt;/span&gt;); &lt;span class="hljs-built_in"&gt;module&lt;/span&gt;.&lt;span class="hljs-built_in"&gt;exports&lt;/span&gt; = { mode: &lt;span class="hljs-string"&gt;"production"&lt;/span&gt;, entry: path.resolve(&lt;strong&gt;dirname, &lt;span&gt;"./src/index.ts"&lt;/span&gt;), &lt;span&gt;module&lt;/span&gt;: { rules: [ { test: &lt;span&gt;/.ts?$/&lt;/span&gt;, use: &lt;span&gt;"ts-loader"&lt;/span&gt;, exclude: &lt;span&gt;/node_modules/&lt;/span&gt;, }, ], }, resolve: { extensions: [ &lt;span&gt;".ts"&lt;/span&gt;, &lt;span&gt;".js"&lt;/span&gt;], }, output: { filename: &lt;span&gt;"script.js"&lt;/span&gt;, path: path.resolve(&lt;/strong&gt;dirname, &lt;span class="hljs-string"&gt;"public"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"static"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"bundle"&lt;/span&gt;), }, }; &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; what does this file do? well it essential gives webpack information such as what file to compile and what folder to compile to. For instance, the entry property above tells webpack what file we are compiling which is index.ts in src which we created earlier (note we used the path module to &lt;em&gt;resolve&lt;/em&gt; the path to the index.ts file no pun intended). filename in the output property tells webpack what to name the compiled javascript bundle and path tells webpack where to place the javascript bundle which we have set to ./public/static/bundle (again we used the path module to resolve the path).You can change the name of the bundles output file to whatever you want just rember to point your html to that javascript bundle in your script tag. &lt;/p&gt; &lt;p&gt; open up the package.json file and under scripts &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629666877517%2FLHOJJl5vF.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629666877517%2FLHOJJl5vF.png" alt="scripts_packagejson1.PNG"&gt;&lt;/a&gt; Add the start and build script shown below &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629666890557%2F--39YbnNb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629666890557%2F--39YbnNb.png" alt="scripts_packagejson2.PNG"&gt;&lt;/a&gt; &lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;that wraps up everything with the configs&lt;/p&gt; &lt;/blockquote&gt; &lt;p&gt;&lt;b&gt;We are almost there &lt;/b&gt;&lt;/p&gt; &lt;p&gt; In our html let up set up our boilerplate and include our css and our bundled javascript (script.js which we named it in the webpack config this is important!!!) &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629666908124%2Ftdt6h_2b8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629666908124%2Ftdt6h_2b8.png" alt="boilerplatehtml.PNG"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt; now in css (in the static folder) create style.css so we can add some styles &lt;br&gt; &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629668955527%2FNyL-G9PEz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629668955527%2FNyL-G9PEz.png" alt="styles.PNG"&gt;&lt;/a&gt; &lt;/p&gt; 
&lt;h3&gt; Running your html&lt;/h3&gt; if you are like me and you are using vscode there is a 95% chance you have liveserver extension installed run the html with liveserver or if you don't just open it in your browser. You should see this page: &lt;br&gt; &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629667025289%2F6nS73F4OI.png" alt="htmlPage.PNG"&gt;  &lt;p&gt;Open your terminal/command prompt&lt;/p&gt; &lt;pre&gt;&lt;code&gt;(assuming you are &lt;span class="hljs-keyword"&gt;in&lt;/span&gt; the projects the root directory) npm &lt;span class="hljs-keyword"&gt;start&lt;/span&gt; &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; This should run the start script that we set to webpack --watch earlier. This compiles our index.ts and recompiles automatically on every change to index.ts . If everything was configured properly this should show up in your terminal. &lt;br&gt; &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629667064660%2FYETssKRSr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629667064660%2FYETssKRSr.png" alt="start_script_output.PNG"&gt;&lt;/a&gt; and our script.js file should be generated in bundle &lt;br&gt; &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629667078483%2FgvbHfiXHz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629667078483%2FgvbHfiXHz.png" alt="bundle_created.PNG"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt; now that we are done with all the boring stuff let's write some typescript in index.ts &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629667094799%2F1qy9MvSgC.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629667094799%2F1qy9MvSgC.png" alt="test1.PNG"&gt;&lt;/a&gt; webpack automatically recompiles our code and the change should take effect in the browser because of liveserver. we should see this: &lt;br&gt; &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629667106358%2FrumoBgbwI.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629667106358%2FrumoBgbwI.png" alt="test1_result.PNG"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt; now let's code up the logic for the counter example. &lt;/p&gt;
&lt;ul&gt; &lt;li&gt;First we need to select the required html elements &lt;ul&gt; &lt;li&gt; our span tag with id counter-value &lt;/li&gt; &lt;li&gt; our button with id increment-btn &lt;/li&gt; &lt;li&gt; our button with id decrement-btn &lt;/li&gt; &lt;ul&gt; &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629667588641%2FRs85orZT4.png" alt="elements_to_select.PNG"&gt; &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629667495057%2Fe5vKbIf_T.png" alt="select_elements.PNG"&gt; &lt;/ul&gt;
&lt;/ul&gt;
&lt;/li&gt; &lt;li&gt; Next we create a new file in src called helpers which will contain two files &lt;ul&gt; &lt;li&gt; increment.ts which will contain our increment function which we will export &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629667758358%2FrNt3dCJba.png" alt="incrementFunction.PNG"&gt; &lt;/li&gt; &lt;li&gt; decrement.ts which will contain our decrement function which we will also export &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629667785122%2FtMwd6VH1q.png" alt="decrementFunction.PNG"&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt; then will import these two functions in index.ts &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629668147650%2FQiyUxrTX3.png" alt="import_modules.PNG"&gt; &lt;/li&gt; &lt;li&gt; Finally the complete snippet &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629668297678%2FB9zSpl3pN.png" alt="complete_code_snippet.PNG"&gt; &lt;/li&gt; &lt;ul&gt;  

&lt;h2&gt; Increment count &lt;/h2&gt;

  &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629669482602%2FGZQaDLuH_.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629669482602%2FGZQaDLuH_.png" alt="count1.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629669492238%2FcaKa8lEqk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629669492238%2FcaKa8lEqk.png" alt="count2.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629669347988%2FOQet9xTcT.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629669347988%2FOQet9xTcT.png" alt="count3.PNG"&gt;&lt;/a&gt;&lt;/p&gt; 

&lt;h2&gt; Decrement count &lt;/h2&gt;

  &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629669355006%2FyNZrUPWLD.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629669355006%2FyNZrUPWLD.png" alt="uncount1.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629669363517%2FEGaQFqWXV.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629669363517%2FEGaQFqWXV.png" alt="uncount2.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629669372391%2FALCVgcWXE.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629669372391%2FALCVgcWXE.png" alt="uncount3.PNG"&gt;&lt;/a&gt;&lt;/p&gt; 

&lt;h2&gt; Summary &lt;/h2&gt;


 &lt;p&gt; Now that we have everything is working fine it might appear like magic or maybe not but either way it is not magic. What essentially is happening is like I said before webpack would bundle all our typescript code including including all modules into a single file which we named script.js. The compiled code looks like this: &lt;br&gt; &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629671587627%2FwDztqY4XS.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1629671587627%2FwDztqY4XS.png" alt="compiled_output.PNG"&gt;&lt;/a&gt; looks kinda ugly right? well this what is being run in the browser and we make changes in our typescript code webpack will recompile into the file which will trigger liveserver to reload, showing how changes automatically in the browser. This is a very simple example so you might node see the benefits straight away but in bigger projects relative to this were you don't want to use a framework this in my oppinon can be really helpful. &lt;/p&gt; &lt;h1 id="conclusion"&gt;Conclusion&lt;/h1&gt; &lt;p&gt;Setting this up might seen like a hassle but using typescript with plain html and css has a lot advantages than with plain Javascript for example type checking, and also enables us to split out code into modules which makes everything much cleaner and easier to debug and much more. If you don't want to bother yourself with setting this up yourself you can make your own vanilla typescript project from this &lt;a href="https://github.com/Xavier577/vanilla-typescript-project-template" rel="noopener noreferrer"&gt;boilerplate&lt;/a&gt; I set up so you don't have to set it up yourself. &lt;/p&gt; &lt;h1 id="a-little-bit-about-me-the-author"&gt;A little bit about me the Author&lt;/h1&gt; &lt;p&gt;If you have read this article to the end, I want you to know that i really appreciate it. My name is Joseph Tsegen, I have training to become a programmer now for 7 months now learning about the web and other technologies. I am aspiring to become a fullstack developer on the path to learn the GNERPT (Graphql Node Express React Postgresql Typescript), I also have interest in Python, Django and Kotlin. I am new to the community here on hashnode, this is in fact my first article please give it a like if you found it interesting or useful and comment on what you think about it and also what you think about building projects with this approach without any framework and what kind of projects you use this for. Feedbacks will be very helpful as it will help access myself and make better content, all feedbacks would be very appreciated. Let me know what you think I could have done better, thank you for reading.&lt;/p&gt; &lt;/ul&gt;

&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Setting up a nodejs project with typescript and deploying to heroku</title>
      <dc:creator>Xavier577</dc:creator>
      <pubDate>Mon, 04 Oct 2021 13:39:47 +0000</pubDate>
      <link>https://dev.to/xavier577/setting-up-a-nodejs-project-with-typescript-and-deploying-to-heroku-4mff</link>
      <guid>https://dev.to/xavier577/setting-up-a-nodejs-project-with-typescript-and-deploying-to-heroku-4mff</guid>
      <description>&lt;p&gt;Setting up nodejs with typescript can be quite troublesome if not done properly. To make this worse you probably won't see the issue with the way you set your project up until you want to deploy it. Today we are gonna go over how exactly we can set up nodejs with typescript in a way that would make deployment easy.&lt;/p&gt; &lt;h1 id="getting-started"&gt;Getting started&lt;/h1&gt; &lt;p&gt;For this tutorial we are gonna be using the following packages: &lt;/p&gt; &lt;ul&gt; &lt;li&gt; yarn &lt;/li&gt; &lt;li&gt; nodejs &lt;/li&gt; &lt;li&gt; typescript &lt;/li&gt; &lt;li&gt; ts-node &lt;/li&gt; &lt;li&gt; express &lt;/li&gt; &lt;li&gt; nodemon &lt;/li&gt; &lt;li&gt; @types/node (type definitions for nodejs) &lt;/li&gt; &lt;li&gt; @types/express (type definition for typescript) &lt;/li&gt; &lt;/ul&gt; &lt;h1 id="initializing-the-project"&gt;Initializing the project&lt;/h1&gt; &lt;p&gt;we are going to initialize the project with yarn and git&lt;/p&gt; &lt;pre&gt;&lt;code&gt;yarn &lt;span class="hljs-keyword"&gt;init&lt;/span&gt; -y &lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;git &lt;span class="hljs-keyword"&gt;init&lt;/span&gt; &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;we should have our package.json file create for us like so&lt;/p&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632520932783%2F2sCNW9nK1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632520932783%2F2sCNW9nK1.png" alt="package_json_created.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h1 id="installing-the-dependencies-for-the-project"&gt;Installing the dependencies for the project&lt;/h1&gt; &lt;p&gt;To make our lives easier let's install express&lt;/p&gt; &lt;pre&gt;&lt;code&gt;yarn &lt;span class="hljs-keyword"&gt;add&lt;/span&gt; express &lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt; &lt;p&gt;Installing typescript and ts-node as dev dependencies&lt;/p&gt; &lt;/blockquote&gt; &lt;pre&gt;&lt;code&gt;yarn &lt;span class="hljs-keyword"&gt;add&lt;/span&gt; -D typescript ts-node &lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt; &lt;p&gt;installing the type definition for node and express&lt;/p&gt; &lt;/blockquote&gt; &lt;pre&gt;&lt;code&gt;yarn &lt;span class="hljs-keyword"&gt;add&lt;/span&gt; -D @&lt;span class="hljs-keyword"&gt;types&lt;/span&gt;/node @&lt;span class="hljs-keyword"&gt;types&lt;/span&gt;/express &lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt; &lt;p&gt;and finally nodemon to run our server in development&lt;/p&gt; &lt;/blockquote&gt; &lt;pre&gt;&lt;code&gt; yarn &lt;span class="hljs-keyword"&gt;add&lt;/span&gt; -D nodemon &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After installing our dependencies it should be included in the package.json file&lt;/p&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632521040738%2F8iLV5N_qf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632521040738%2F8iLV5N_qf.png" alt="package_json_postinstall.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;And our node_modules folder must have been created&lt;/p&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632521068567%2FexkR_qz4m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632521068567%2FexkR_qz4m.png" alt="folder_structure_step2.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Let's create a .gitignore file and add our node_modules in there to prevent it from being tracked by git&lt;/p&gt; &lt;pre&gt;&lt;code&gt;&lt;span class="hljs-comment"&gt;// (in .gitignore)&lt;/span&gt; &lt;span class="hljs-selector-tag"&gt;node_modules&lt;/span&gt; &lt;/code&gt;&lt;/pre&gt;
&lt;h1 id="adding-the-scripts"&gt;Adding the scripts&lt;/h1&gt; &lt;blockquote&gt; &lt;p&gt;add the following to your package.json file&lt;/p&gt; &lt;/blockquote&gt; &lt;pre&gt;&lt;code&gt; &lt;span class="hljs-string"&gt;"scripts"&lt;/span&gt;: { &lt;span class="hljs-string"&gt;"start"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"node dist/index.js"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"build"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"tsc"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"dev"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"nodemon --exec ts-node ./src/index.ts --mode development"&lt;/span&gt; } &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;our package.json should look like this&lt;/p&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632521099391%2F5ddsWf2Tp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632521099391%2F5ddsWf2Tp.png" alt="package_json_postscript.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h2&gt;Explaination for the script&lt;/h2&gt; &lt;ul&gt; &lt;li&gt; The build script is responsible for making our javascript build of the project for deployment (it would build all our files into a dist folder with the tsc command which we would set up in a second) &lt;/li&gt; &lt;li&gt;start is what would run the app when we deploy it to service such as heroku&lt;/li&gt; &lt;li&gt;dev is to run our app in development&lt;/li&gt; &lt;/ul&gt; &lt;h1&gt; Generating our tsconfig file &lt;/h1&gt; Normally we would run &lt;code&gt;tsc --init&lt;/code&gt; to create our tsconfig.json file but in this tutorial i would use a library created by one of my favourite youtubers (&lt;a href="https://www.youtube.com/c/BenAwad97" rel="noopener noreferrer"&gt;Ben Awad&lt;/a&gt;) called tsconfig.json. To use the package we'll run: &lt;code&gt;npx tsconfig.json&lt;/code&gt; &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632521146710%2FkN5vap8eS.png" alt="benawads_tsconfig.PNG"&gt; I'll select nodejs and that should create a tsconfig for us. &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632521166007%2FdGNke16s8.png" alt="tsconfig_benawad.PNG"&gt; so it contains some set rule for our project, feel free to change whatever you like to your liking but the most important options here are "outDir" which tells the typescript compiler where to compile our javascript file, "excludes" which tells typescript what files to ignore, "include" tells typescript what files to check during compilation, "target" the version of javascript we are compiling to (which Ben has set to es2017) and "module" which tells typescript what module syntax should be used. &lt;br&gt; The "outDir" has been set to dist but you can name it whatever you want (but remember to change that in the package.json file) but by convention it is usually best practise to call it dist or build. &lt;br&gt; we are gonna want to include the dist folder to the .gitignore file as this folder is only needed during deployment . &lt;h2&gt;Creating our source folder &lt;/h2&gt; &lt;p&gt;First we are gonna want to create a folder called "src", this is where we would write all our typescript code&lt;/p&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632521499317%2F5f4OwY_bd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632521499317%2F5f4OwY_bd.png" alt="final_folder_structure.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;I'll create a file called index.ts which would be our main input&lt;/p&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632521523230%2Fe9T9i0VCv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632521523230%2Fe9T9i0VCv.png" alt="indexts_stage0.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h1 id="now-lets-write-some-code"&gt;Now let's write some code&lt;/h1&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632521679053%2FGesTeL_86.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632521679053%2FGesTeL_86.png" alt="code_snippet_1.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Here we are importing express, setting the a new express application to the variable app. We set the PORT variable to use the process environment port if available and 8080 otherwise then we listen then PORT variable. And we handle our get request with the app.get() method by sending to the client "hello" + client hostname(which is localhost in this case) &lt;br&gt;&lt;/p&gt; &lt;h2&gt;now let's run our server&lt;/h2&gt; &lt;br&gt; &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522291464%2FjiXMzOlZC.png" alt="start_dev_server.PNG"&gt; &lt;br&gt; &lt;h2&gt; now let's run it in the browser &lt;/h2&gt; &lt;br&gt; &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522322875%2Fz0jZnutEr.png" alt="browser_test_1.PNG"&gt; &lt;h2&gt;Let's make a change&lt;/h2&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522346876%2FmqHJ-m8HP.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522346876%2FmqHJ-m8HP.png" alt="ts-error-1.PNG"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;That threw an error because in the tsconfig.json the "noUnusedParameters" property is set to true which prevent the unused parameters in the code (which is some best practice stuff :( ).&lt;/p&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522387777%2F58di_uSpW.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522387777%2F58di_uSpW.png" alt="ts_conflit1.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;To remove the error you can either disable the rule by setting "noUnUsedParameters" to false in the tsconfig.json file or simply use the editor quick fix option which I am gonna use.&lt;/p&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522411694%2FWEHVSAmPz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522411694%2FWEHVSAmPz.png" alt="quick_fix_1.PNG"&gt;&lt;/a&gt; &lt;br&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522439204%2FOaU2WNh7w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522439204%2FOaU2WNh7w.png" alt="quick_transition_1.PNG"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522486329%2FmQja1s-F3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522486329%2FmQja1s-F3.png" alt="fix1.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;That was fixed by placing an underscore on the unused parameter, now let's restart the server&lt;/p&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522500377%2FpF0MeLtTl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522500377%2FpF0MeLtTl.png" alt="restart1.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522509672%2FFvhUmH1LD.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522509672%2FFvhUmH1LD.png" alt="change1.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;It works yay!&lt;/p&gt; &lt;h1 id="deploying-our-app-to-heroku"&gt;Deploying our app to heroku&lt;/h1&gt; &lt;p&gt;Now let's see how exactly we can deploy our app which is the part which cause alot of issues especially when unusing typescript with nodejs.&lt;/p&gt; &lt;p&gt;first i am gonna run the build command so that we can see how our app would be built.&lt;/p&gt; &lt;p&gt;we'll run:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;&lt;span class="hljs-attribute"&gt;yarn&lt;/span&gt; run build &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This should create a folder dist which contains our compiled code&lt;/p&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522583571%2Fz3faCKpOS.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522583571%2Fz3faCKpOS.png" alt="build_files.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;This is gonna be what would be run on heroku when we deploy&lt;/p&gt; &lt;p&gt;I am gonna delete this file for now.&lt;/p&gt; &lt;p&gt;Assuming we did everything correctly up until this point, i am gonna list the step for deploying this add to heroku via the heroku-cli. If you don't have installed you can install it with &lt;code&gt;npm install -g heroku&lt;/code&gt;&lt;/p&gt; 
&lt;ul&gt;
 &lt;li&gt; &lt;h2&gt;Logging in to heroku&lt;/h2&gt;  &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522601501%2Fgf1ZX6Q28.png" alt="heroku_login.PNG"&gt; &lt;/li&gt; &lt;li&gt; &lt;h2&gt;Adding changes to git&lt;/h2&gt; &lt;pre&gt;&lt;code&gt;git &lt;span class="hljs-keyword"&gt;add&lt;/span&gt; . &lt;/code&gt;&lt;/pre&gt;



&lt;/li&gt;

 


&lt;li&gt; &lt;h2&gt;Committing changes&lt;/h2&gt;

&lt;/li&gt; &lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;git &lt;span class="hljs-keyword"&gt;commit&lt;/span&gt; -am "deploy" &lt;/code&gt;&lt;/pre&gt;
 
&lt;li&gt; &lt;h2&gt;Adding heroku remote&lt;/h2&gt; 
&lt;/li&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522623092%2FA5PohYpJg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522623092%2FA5PohYpJg.png" alt="heroku_remote.PNG"&gt;&lt;/a&gt;&lt;/p&gt;  
&lt;li&gt; &lt;h2&gt;Pushing to heroku&lt;/h2&gt;

&lt;/li&gt; &lt;pre&gt;&lt;code&gt;git &lt;span class="hljs-keyword"&gt;push&lt;/span&gt; heroku master &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522649820%2FbtsEx5kyM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522649820%2FbtsEx5kyM.png" alt="deploying1.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522665183%2Fc-3Ze3CeK.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522665183%2Fc-3Ze3CeK.png" alt="deploying_complete.PNG"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;ul&gt; &lt;h1 id="deployed-site"&gt;Deployed site 🚀🚀🚀&lt;/h1&gt; &lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522674943%2FDIqi7J385.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632522674943%2FDIqi7J385.png" alt="deployed_site.PNG"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;yay! we have our site deployed.&lt;/p&gt; &lt;h1 id="conclusion"&gt;Conclusion&lt;/h1&gt; &lt;p&gt;This is just a very basic example but the main purpose of this guide was to help give an idea on how you can host/deploy a nodejs typescript project of any sort. You can change the rules in the tsconfig.json file to match your use case but make sure the "outDir" is correctly specified. I have had issues deploying typescript nodejs projects myself but now I feel a little more confident doing it now so I decided to share it with the community. I hope this was able to help out in someway. Lemme know if there are better ways to do this. Please do like and comment if you found this interesting.&lt;/p&gt; &lt;/ul&gt;

</description>
    </item>
  </channel>
</rss>
