<?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>Nodejs &#8211; Otricks.com</title>
	<atom:link href="https://otricks.com/category/javascript/nodejs/feed/" rel="self" type="application/rss+xml" />
	<link>https://otricks.com</link>
	<description>It&#039;s the big &#039;O&#039; in technology</description>
	<lastBuildDate>Wed, 29 Dec 2021 12:44:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>
	<item>
		<title>Create front-end app for space-XYZ cargo booking system.</title>
		<link>https://otricks.com/create-front-end-app-for-space-xyz-cargo-booking-system/</link>
		
		<dc:creator><![CDATA[Anjum Nawab]]></dc:creator>
		<pubDate>Wed, 29 Dec 2021 12:44:48 +0000</pubDate>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Nodejs]]></category>
		<guid isPermaLink="false">https://otricks.com/?p=2378</guid>

					<description><![CDATA[<p>This is multi-part post and this is 2 or 3 part. Our base design would be like space-x website with header, background image and some&#46;&#46;&#46;</p>
<p>The post <a rel="nofollow" href="https://otricks.com/create-front-end-app-for-space-xyz-cargo-booking-system/">Create front-end app for space-XYZ cargo booking system.</a> appeared first on <a rel="nofollow" href="https://otricks.com">Otricks.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>This is multi-part post and this is 2 or 3 part.</p>



<p>Our base design would be like space-x website with header, background image and some text, we will create a full functional strapi server from where all data comes eventually. For now we will create dummy text and dummy image placeholder, later we will integrate with API from strapi.</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="561" src="https://otricks.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-20-at-11.27.23-PM-1024x561.png" alt="" class="wp-image-2388" srcset="https://otricks.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-20-at-11.27.23-PM-1024x561.png 1024w, https://otricks.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-20-at-11.27.23-PM-300x164.png 300w, https://otricks.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-20-at-11.27.23-PM-768x421.png 768w, https://otricks.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-20-at-11.27.23-PM-1536x842.png 1536w, https://otricks.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-20-at-11.27.23-PM-2048x1123.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>Create new empty folder and name it <strong><em>space-xyz</em></strong> then cd into it, open terminal window I will be using <a rel="noreferrer noopener" href="https://iterm2.com/" target="_blank">iTerm2</a> for my terminal window and run below command it will generate new angular project.</p>



<div style="height: 250px; position:relative; margin-bottom: 50px;" class="wp-block-simple-code-block-ace"><div style="position:absolute;top:-20px;right:0px;cursor:pointer" class="copy-simple-code-block"><svg aria-hidden="true" role="img" focusable="false" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewbox="0 0 20 20" class="dashicon dashicons-admin-page"><path d="M6 15V2h10v13H6zm-1 1h8v2H3V5h2v11z"></path></svg></div><pre class="wp-block-simple-code-block-ace" style="position:absolute;top:0;right:0;bottom:0;left:0" data-mode="sh" data-theme="monokai" data-fontsize="13" data-lines="5" data-showlines="true" data-copy="true">npx -p  @angular/cli@10.2.1 ng new space-xyz </pre></div>



<div style="height: 250px; position:relative; margin-bottom: 50px;" class="wp-block-simple-code-block-ace"><pre class="wp-block-simple-code-block-ace" style="position:absolute;top:0;right:0;bottom:0;left:0" data-mode="sh" data-theme="monokai" data-fontsize="13" data-lines="20" data-showlines="true" data-copy="false">? Would you like to add Angular routing? Yes
? Which stylesheet format would you like to use? SCSS   [ https://sass-lang.com/documentation/syntax#scss                ]
CREATE space-xyz/README.md (1017 bytes)
CREATE space-xyz/.editorconfig (274 bytes)
CREATE space-xyz/.gitignore (631 bytes)
CREATE space-xyz/angular.json (3678 bytes)
CREATE space-xyz/package.json (1252 bytes)
CREATE space-xyz/tsconfig.json (458 bytes)
CREATE space-xyz/tslint.json (3185 bytes)
CREATE space-xyz/.browserslistrc (853 bytes)
CREATE space-xyz/karma.conf.js (1021 bytes)
CREATE space-xyz/tsconfig.app.json (287 bytes)
CREATE space-xyz/tsconfig.spec.json (333 bytes)
CREATE space-xyz/src/favicon.ico (948 bytes)
CREATE space-xyz/src/index.html (294 bytes)
CREATE space-xyz/src/main.ts (372 bytes)
CREATE space-xyz/src/polyfills.ts (2830 bytes)
CREATE space-xyz/src/styles.scss (80 bytes)
CREATE space-xyz/src/test.ts (753 bytes)
CREATE space-xyz/src/assets/.gitkeep (0 bytes)
CREATE space-xyz/src/environments/environment.prod.ts (51 bytes)
CREATE space-xyz/src/environments/environment.ts (662 bytes)
CREATE space-xyz/src/app/app-routing.module.ts (245 bytes)
CREATE space-xyz/src/app/app.module.ts (393 bytes)
CREATE space-xyz/src/app/app.component.scss (0 bytes)
CREATE space-xyz/src/app/app.component.html (25757 bytes)
CREATE space-xyz/src/app/app.component.spec.ts (1066 bytes)
CREATE space-xyz/src/app/app.component.ts (214 bytes)
CREATE space-xyz/e2e/protractor.conf.js (869 bytes)
CREATE space-xyz/e2e/tsconfig.json (294 bytes)
CREATE space-xyz/e2e/src/app.e2e-spec.ts (642 bytes)
CREATE space-xyz/e2e/src/app.po.ts (301 bytes)
&#x2714; Packages installed successfully.
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: 	git config --global init.defaultBranch &lt;name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: 	git branch -m &lt;name>
    Successfully initialized git.</pre></div>



<p>Open frontend project in your favorite code editor, I will be using visual studio code (vscode) its super fast and build on node stack too.</p>



<p>We will generate header component user angular CLI command, It will be very simple header to hold our navigation and logo for our application.</p>



<div style="height: 250px; position:relative; margin-bottom: 50px;" class="wp-block-simple-code-block-ace"><div style="position:absolute;top:-20px;right:0px;cursor:pointer" class="copy-simple-code-block"><svg aria-hidden="true" role="img" focusable="false" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewbox="0 0 20 20" class="dashicon dashicons-admin-page"><path d="M6 15V2h10v13H6zm-1 1h8v2H3V5h2v11z"></path></svg></div><pre class="wp-block-simple-code-block-ace" style="position:absolute;top:0;right:0;bottom:0;left:0" data-mode="sh" data-theme="monokai" data-fontsize="13" data-lines="5" data-showlines="true" data-copy="true">npx ng generate component header </pre></div>



<div style="height: 250px; position:relative; margin-bottom: 50px;" class="wp-block-simple-code-block-ace"><pre class="wp-block-simple-code-block-ace" style="position:absolute;top:0;right:0;bottom:0;left:0" data-mode="sh" data-theme="monokai" data-fontsize="14" data-lines="10" data-showlines="true" data-copy="false">? Would you like to share anonymous usage data about this project with the Angular Team at
Google under Google’s Privacy Policy at https://policies.google.com/privacy? For more
details and how to change this setting, see http://angular.io/analytics. Yes

Thank you for sharing anonymous usage data. Would you change your mind, the following
command will disable this feature entirely:

    ng analytics project off

CREATE src/app/header/header.component.scss (0 bytes)
CREATE src/app/header/header.component.html (21 bytes)
CREATE src/app/header/header.component.spec.ts (626 bytes)
CREATE src/app/header/header.component.ts (276 bytes)
UPDATE src/app/app.module.ts (475 bytes)</pre></div>



<p>Insider header component &#8220;<strong><em>header/header.component.html</em></strong>&#8221; </p>



<p>We will use our server to provide all the data for now we will just use as place holder.</p>



<div style="height: 250px; position:relative; margin-bottom: 50px;" class="wp-block-simple-code-block-ace"><div style="position:absolute;top:-20px;right:0px;cursor:pointer" class="copy-simple-code-block"><svg aria-hidden="true" role="img" focusable="false" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewbox="0 0 20 20" class="dashicon dashicons-admin-page"><path d="M6 15V2h10v13H6zm-1 1h8v2H3V5h2v11z"></path></svg></div><pre class="wp-block-simple-code-block-ace" style="position:absolute;top:0;right:0;bottom:0;left:0" data-mode="html" data-theme="monokai" data-fontsize="13" data-lines="Infinity" data-showlines="true" data-copy="true">&lt;div class="header-holder">
  &lt;div class="logo">
    &lt;h1>Space-XYZ&lt;/h1>
  &lt;/div>
  &lt;div class="menu">
    &lt;ul>
      &lt;li>
        &lt;a routerLink="/first-component" routerLinkActive="active">link 1&lt;/a>
      &lt;/li>
      &lt;li>
        &lt;a routerLink="/first-component" routerLinkActive="active">link 2&lt;/a>
      &lt;/li>
      &lt;li>
        &lt;a routerLink="/first-component" routerLinkActive="active">link 3&lt;/a>
      &lt;/li>
      &lt;li>
        &lt;a routerLink="/first-component" routerLinkActive="active">link 4&lt;/a>
      &lt;/li>
      &lt;li>
        &lt;a routerLink="/first-component" routerLinkActive="active">link 5&lt;/a>
      &lt;/li>
    &lt;/ul>
  &lt;/div>
&lt;/div>
</pre></div>



<p>Let&#8217;s create body component to hold some text and other data.</p>



<div style="height: 250px; position:relative; margin-bottom: 50px;" class="wp-block-simple-code-block-ace"><pre class="wp-block-simple-code-block-ace" style="position:absolute;top:0;right:0;bottom:0;left:0" data-mode="sh" data-theme="monokai" data-fontsize="14" data-lines="Infinity" data-showlines="true" data-copy="false">npx ng generate component body </pre></div>



<p>Insider body component &#8220;<strong><em>body/body.component.html</em></strong>&#8220;</p>



<div style="height: 250px; position:relative; margin-bottom: 50px;" class="wp-block-simple-code-block-ace"><pre class="wp-block-simple-code-block-ace" style="position:absolute;top:0;right:0;bottom:0;left:0" data-mode="html" data-theme="monokai" data-fontsize="14" data-lines="Infinity" data-showlines="true" data-copy="false">&lt;div class="body-holder">
  &lt;h1>Some Name comes form server&lt;/h1>
  &lt;p>Some text comes from server&lt;/p>
  &lt;a href="">Book it now&lt;/a>
&lt;/div></pre></div>



<p>Insider body component &#8220;<strong><em>body/body.component.scss</em></strong>&#8220;</p>



<div style="height: 250px; position:relative; margin-bottom: 50px;" class="wp-block-simple-code-block-ace"><pre class="wp-block-simple-code-block-ace" style="position:absolute;top:0;right:0;bottom:0;left:0" data-mode="scss" data-theme="monokai" data-fontsize="14" data-lines="Infinity" data-showlines="true" data-copy="false">// body/body.component.scss

.body-holder {
  display: flex;
  align-items: center;
  flex-direction: column;
  margin-top: 15%;

  h1 {
    font-size: 60px;
    text-transform: uppercase;
    color: #fff;
  }

  p {
    color: #fff;
    text-transform: uppercase;
  }
  a {
    text-decoration: none;
    background: green;
    border: 1px solid #037203;
    color: #fff;
    padding: 20px;
    font-size: 16px;
    text-transform: uppercase;
  }
}
</pre></div>



<p>Update routing &#8220;<strong><em>app-routing.module.ts</em></strong>&#8221; file with below code.</p>



<div style="height: 250px; position:relative; margin-bottom: 50px;" class="wp-block-simple-code-block-ace"><pre class="wp-block-simple-code-block-ace" style="position:absolute;top:0;right:0;bottom:0;left:0" data-mode="typescript" data-theme="monokai" data-fontsize="14" data-lines="Infinity" data-showlines="true" data-copy="false">// app-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { BodyComponent } from './body/body.component';

const routes: Routes = [
  {
    path: ':id',
    component: BodyComponent,
  },
  {
    path: '',
    component: BodyComponent,
  },
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule],
})
export class AppRoutingModule {}
</pre></div>



<p>Update app component  &#8220;<strong><em>app.component.html</em></strong>&#8221; file  and &#8220;<strong><em>app.component.ts&#8221; </em></strong>with below code. Later we will get background image from API response, for now we are hardcoding <strong><em>backgroundImage</em></strong> path </p>



<div style="height: 250px; position:relative; margin-bottom: 50px;" class="wp-block-simple-code-block-ace"><pre class="wp-block-simple-code-block-ace" style="position:absolute;top:0;right:0;bottom:0;left:0" data-mode="html" data-theme="monokai" data-fontsize="14" data-lines="Infinity" data-showlines="true" data-copy="false">&lt;!--app.component.html-->

&lt;div
  class="body"
  [ngStyle]="{
    background:
      'url(' + backgroundImage + ') #000 no-repeat center bottom / contain'
  }"
>
  &lt;div class="container">
    &lt;app-header>&lt;/app-header>
    &lt;router-outlet>&lt;/router-outlet>
  &lt;/div>
&lt;/div>
</pre></div>



<div style="height: 250px; position:relative; margin-bottom: 50px;" class="wp-block-simple-code-block-ace"><pre class="wp-block-simple-code-block-ace" style="position:absolute;top:0;right:0;bottom:0;left:0" data-mode="typescript" data-theme="monokai" data-fontsize="14" data-lines="Infinity" data-showlines="true" data-copy="false">// app.component.ts

import { Component } from '@angular/core';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent {
  title = 'space-xyz';
  backgroundImage = null;

  constructor() {
    this.backgroundImage = '../../assets/f9_feature.webp';
  }
}
</pre></div>



<p>And last update &#8220;<strong><em>app.module.ts</em></strong>&#8221; to reflect those changes.</p>



<div style="height: 250px; position:relative; margin-bottom: 50px;" class="wp-block-simple-code-block-ace"><pre class="wp-block-simple-code-block-ace" style="position:absolute;top:0;right:0;bottom:0;left:0" data-mode="typescript" data-theme="monokai" data-fontsize="14" data-lines="Infinity" data-showlines="true" data-copy="false">//app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { BodyComponent } from './body/body.component';

@NgModule({
  declarations: [AppComponent, HeaderComponent, BodyComponent],
  imports: [BrowserModule, AppRoutingModule],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}</pre></div>



<p>Finally run angular application to view our frontend app. You will be able to see something like below screen shot. </p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="730" src="https://otricks.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-28-at-9.48.35-PM-1024x730.png" alt="" class="wp-image-2392" srcset="https://otricks.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-28-at-9.48.35-PM-1024x730.png 1024w, https://otricks.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-28-at-9.48.35-PM-300x214.png 300w, https://otricks.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-28-at-9.48.35-PM-768x547.png 768w, https://otricks.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-28-at-9.48.35-PM-1536x1095.png 1536w, https://otricks.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-28-at-9.48.35-PM-2048x1460.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>For some reason if you miss any step you can check <a rel="noreferrer noopener" href="https://github.com/anjum121/space-xyz/tree/master/fontend" target="_blank">https://github.com/anjum121/space-xyz/tree/master/fontend</a> link for final code.</p>



<p>Next step is to create Strapi system, let&#8217;s go to backend part. 🙂 </p>
<p>The post <a rel="nofollow" href="https://otricks.com/create-front-end-app-for-space-xyz-cargo-booking-system/">Create front-end app for space-XYZ cargo booking system.</a> appeared first on <a rel="nofollow" href="https://otricks.com">Otricks.com</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to use webSocket/Socket.io inside Strapi content management system.</title>
		<link>https://otricks.com/how-to-use-websocket-socket-io-inside-strapi-content-management-system/</link>
		
		<dc:creator><![CDATA[Anjum Nawab]]></dc:creator>
		<pubDate>Wed, 29 Dec 2021 12:39:28 +0000</pubDate>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Nodejs]]></category>
		<category><![CDATA[Server]]></category>
		<guid isPermaLink="false">https://otricks.com/?p=2369</guid>

					<description><![CDATA[<p>What is WebSocket? WebSocket is very useful pice of technology to communicate seamlessly from server to client, unlike HTTP it use full-duplex data transmission meaning, data&#46;&#46;&#46;</p>
<p>The post <a rel="nofollow" href="https://otricks.com/how-to-use-websocket-socket-io-inside-strapi-content-management-system/">How to use webSocket/Socket.io inside Strapi content management system.</a> appeared first on <a rel="nofollow" href="https://otricks.com">Otricks.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading"><strong>What is WebSocket?</strong></h3>



<p>WebSocket is very useful pice of technology  to communicate seamlessly from server to client, unlike HTTP it use full-duplex data transmission meaning,  data can be transmitted in both directions on a signal carrier at the same time. To interact with webSocket we can use <a rel="noreferrer noopener" href="http://socket.io" target="_blank">socket.io</a> library which hides most of the stuff and provide clean API.</p>



<h3 class="wp-block-heading"><strong>What is strapi? </strong></h3>



<p>It&#8217;s headless content management system, if this headless makes no sense then think like <a href="https://wordpress.org/" target="_blank" rel="noreferrer noopener">wordpress</a> or <a href="https://www.joomla.org/">Joomla</a>  content management systems (cms) they comes with themes which user can install and see something in action, however in headless CMS there are no theme system, user needs to create their own theme for website or they can consume data on mobile apps.</p>



<p><a rel="noreferrer noopener" href="https://strapi.io/" target="_blank">Strapi</a> is open source nodejs based system, its based on <a rel="noreferrer noopener" href="https://koajs.com/" target="_blank">Koa.js.com</a> or follows same style of coding. Its comes with Rest API as well as <a rel="noreferrer noopener" href="https://graphql.org/" target="_blank">graphql</a> support too.</p>



<p>I don&#8217;t want to create chat-room example for this guide. May be We can create to booking system to send payload to Mars using <a rel="noreferrer noopener" href="https://www.spacex.com/vehicles/dragon/" target="_blank">space-x</a> shuttle service, where user can book a cargo in the space-x rocket once space is allocated from space-x&#8217;s team, the user will get notification via WebSocket about cargo space. </p>



<p>It&#8217;s going to be very long post, hence I will create it in multiple steps. I will be pushing code to Github in every step so do checkout all the steps of the code.</p>



<h3 class="wp-block-heading">I will try to implement following </h3>



<ul class="wp-block-list"><li>Create Angular application for frontend system (FE).</li><li>Create user login (FE)</li><li>Create protected route (FE)</li><li>Create Strapi application for backend system (BE).</li><li>Create sample API (BE).</li><li>Create dummy user (BE).</li><li>Start communication from Angular application to Strapi application.</li><li>Identify user and based on user send socket messages.</li></ul>



<p>Lets start building our frontend system first, I will call our fictional cargo booking company. space-XYZ .</p>



<p>Please click her to checkout frontend system.</p>



<p></p>
<p>The post <a rel="nofollow" href="https://otricks.com/how-to-use-websocket-socket-io-inside-strapi-content-management-system/">How to use webSocket/Socket.io inside Strapi content management system.</a> appeared first on <a rel="nofollow" href="https://otricks.com">Otricks.com</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Ideal setup for working with nodejs typescript in VS code?</title>
		<link>https://otricks.com/what-is-the-ideal-setup-for-working-with-nodejs-typescript-in-vs-code/</link>
		
		<dc:creator><![CDATA[Anjum Nawab]]></dc:creator>
		<pubDate>Fri, 20 Mar 2020 19:30:46 +0000</pubDate>
				<category><![CDATA[Nodejs]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Tips]]></category>
		<guid isPermaLink="false">https://otricks.com/?p=2105</guid>

					<description><![CDATA[<p>I was a very big fan of nodemon for a long time. for those who don&#8217;t have any idea about nodemon, it&#8217;s file watcher that&#8217;s&#46;&#46;&#46;</p>
<p>The post <a rel="nofollow" href="https://otricks.com/what-is-the-ideal-setup-for-working-with-nodejs-typescript-in-vs-code/">Ideal setup for working with nodejs typescript in VS code?</a> appeared first on <a rel="nofollow" href="https://otricks.com">Otricks.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>I was a very big fan of <a href="https://www.npmjs.com/package/nodemon">nodemon</a> for a long time. for those who don&#8217;t have any idea about nodemon, it&#8217;s file watcher that&#8217;s looking for any change in any file and refreshes the project to see those changes. In nodejs ecosystem, its uses for debugging purpose which was very helpful. however on the other side its eat up all the system resource. </p>



<p>Now I have switched from nodemon to new amazing <a href="https://www.npmjs.com/package/ts-node-dev">ts-node-dev</a> as stated in npm site</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>It restarts target node process when any of required files changes (as standard <code>node-dev</code>) but shares <a href="https://github.com/Microsoft/TypeScript/">Typescript</a> compilation process between restarts. This significantly increases speed of restarting comparing to <code>node-dev -r ts-node/register ...</code>, <code>nodemon -x ts-node ...</code> variations because there is no need to instantiate <code>ts-node</code> compilation each time.</p></blockquote>



<p>I will show my vs code setup for typescript which auto recompile and uses ts-node-dev package for any file change event.</p>



<h2 class="wp-block-heading">Setup vs code for typescript </h2>



<p>Create a new project in your computer</p>



<div style="height: 250px; position:relative; margin-bottom: 50px;" class="wp-block-simple-code-block-ace"><pre class="wp-block-simple-code-block-ace" style="position:absolute;top:0;right:0;bottom:0;left:0" data-mode="sh" data-theme="monokai" data-fontsize="14" data-lines="Infinity" data-showlines="true" data-copy="false">mkdir dummyProject
cd dummyProject</pre></div>



<p>I will be using npm as my package manager, let&#8217;s create a new package with default settings with below command </p>



<div style="height: 250px; position:relative; margin-bottom: 50px;" class="wp-block-simple-code-block-ace"><pre class="wp-block-simple-code-block-ace" style="position:absolute;top:0;right:0;bottom:0;left:0" data-mode="sh" data-theme="monokai" data-fontsize="14" data-lines="Infinity" data-showlines="true" data-copy="false">npm init -y</pre></div>



<p>It will generate a new file as a package.json </p>



<div style="height: 250px; position:relative; margin-bottom: 50px;" class="wp-block-simple-code-block-ace"><pre class="wp-block-simple-code-block-ace" style="position:absolute;top:0;right:0;bottom:0;left:0" data-mode="json" data-theme="monokai" data-fontsize="14" data-lines="Infinity" data-showlines="true" data-copy="false">{
  "name": "dummyProject",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" &amp;&amp; exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}</pre></div>



<p>Add typescript,  ts-node-dev and create new src folder with index.ts file inside.</p>



<div style="height: 250px; position:relative; margin-bottom: 50px;" class="wp-block-simple-code-block-ace"><pre class="wp-block-simple-code-block-ace" style="position:absolute;top:0;right:0;bottom:0;left:0" data-mode="sh" data-theme="monokai" data-fontsize="14" data-lines="Infinity" data-showlines="true" data-copy="false">npm install typescript ts-node-dev --save-dev
</pre></div>



<p>Open package.json file and add below script inside the scripts block.</p>



<div style="height: 250px; position:relative; margin-bottom: 50px;" class="wp-block-simple-code-block-ace"><pre class="wp-block-simple-code-block-ace" style="position:absolute;top:0;right:0;bottom:0;left:0" data-mode="json" data-theme="monokai" data-fontsize="14" data-lines="Infinity" data-showlines="true" data-copy="false">"dev": "ts-node-dev --respawn --transpileOnly src/index.ts"
"dev:debug": "ts-node-dev --inspect=4321 --respawn --transpileOnly src/index.ts"</pre></div>



<div style="height: 250px; position:relative; margin-bottom: 50px;" class="wp-block-simple-code-block-ace"><pre class="wp-block-simple-code-block-ace" style="position:absolute;top:0;right:0;bottom:0;left:0" data-mode="json" data-theme="monokai" data-fontsize="14" data-lines="Infinity" data-showlines="true" data-copy="false">{
  "name": "dummyProject",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "ts-node-dev --respawn --transpileOnly src/index.ts",
    "dev:debug": "ts-node-dev --inspect=4321 --respawn --transpileOnly src/index.ts"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
</pre></div>



<h2 class="wp-block-heading">Visual studio code debugging</h2>



<p>Inside visual studio code, we can add a breakpoint in the typescript code which can stop at certain points. Inside your root directory of the current project.</p>



<div style="height: 250px; position:relative; margin-bottom: 50px;" class="wp-block-simple-code-block-ace"><pre class="wp-block-simple-code-block-ace" style="position:absolute;top:0;right:0;bottom:0;left:0" data-mode="sh" data-theme="monokai" data-fontsize="14" data-lines="Infinity" data-showlines="true" data-copy="false">mkdir .vscode
cd .vscode
touch launch.json</pre></div>



<p>Paste the following into your <code>launch.json</code> which we have created the previous step.</p>



<div style="height: 250px; position:relative; margin-bottom: 50px;" class="wp-block-simple-code-block-ace"><pre class="wp-block-simple-code-block-ace" style="position:absolute;top:0;right:0;bottom:0;left:0" data-mode="json" data-theme="monokai" data-fontsize="14" data-lines="Infinity" data-showlines="true" data-copy="false">{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "attach",
      "name": "Attach to dev:debug",
      "protocol": "inspector",
      "port": 4321,
      "restart": true,
      "cwd": "${workspaceRoot}"
    }
  ]
}</pre></div>



<p>Now do <code>npm run dev:debug</code> first in vs code terminal. once its&#8217; started then click on the debug button from the left  menu in VS code. it will open debugger panel something below.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="615" src="https://otricks.com/wp-content/uploads/2020/03/Screen-Shot-2020-03-20-at-23.22.05-1024x615.png" alt="sample vs code with debugger step" class="wp-image-2117" srcset="https://otricks.com/wp-content/uploads/2020/03/Screen-Shot-2020-03-20-at-23.22.05-1024x615.png 1024w, https://otricks.com/wp-content/uploads/2020/03/Screen-Shot-2020-03-20-at-23.22.05-300x180.png 300w, https://otricks.com/wp-content/uploads/2020/03/Screen-Shot-2020-03-20-at-23.22.05-768x461.png 768w, https://otricks.com/wp-content/uploads/2020/03/Screen-Shot-2020-03-20-at-23.22.05-1536x923.png 1536w, https://otricks.com/wp-content/uploads/2020/03/Screen-Shot-2020-03-20-at-23.22.05-2048x1231.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>Check out other tips such as <a href="https://otricks.com/how-to-secure-your-ubuntu-server-from-brute-force-attacks/">How to secure ubuntu server</a> </p>
<p>The post <a rel="nofollow" href="https://otricks.com/what-is-the-ideal-setup-for-working-with-nodejs-typescript-in-vs-code/">Ideal setup for working with nodejs typescript in VS code?</a> appeared first on <a rel="nofollow" href="https://otricks.com">Otricks.com</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
