<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<title type="text">Cross-Platform-Blog.com</title>
<generator uri="https://github.com/mojombo/jekyll">Jekyll</generator>
<link rel="self" type="application/atom+xml" href="http://www.cross-platform-blog.com/feed.xml" />
<link rel="alternate" type="text/html" href="http://www.cross-platform-blog.com" />
<updated>2017-10-28T22:46:31+02:00</updated>
<id>http://www.cross-platform-blog.com/</id>
<author>
  <name>Gregor Biswanger</name>
  <uri>http://www.cross-platform-blog.com/</uri>
  <email>gregor.biswanger@web-enliven.de</email>
</author>


<entry>
  <title type="html"><![CDATA[Electron.NET – Create a minimal MusicPlayer App with ASP.NET Core 2 for the Desktop]]></title>
 <link rel="alternate" type="text/html" href="http://www.cross-platform-blog.com/electron.net/electron.net-musicplayer-app-with-asp.net-core/" />
  <id>http://www.cross-platform-blog.com/electron.net/electron.net-musicplayer-app-with-asp.net-core</id>
  <updated>2017-10-27T00:00:00-00:00</updated>
  <published>2017-10-27T00:00:00+02:00</published>
  
  <author>
    <name>Gregor Biswanger</name>
    <uri>http://www.cross-platform-blog.com</uri>
    <email>gregor.biswanger@web-enliven.de</email>
  </author>
  <content type="html">
    &lt;p&gt;Actually, this blog is addressed to Cross-Platform development with JavaScript. But this time, I have a very special treat for you: &lt;a href=&quot;https://github.com/ElectronNET/Electron.NET&quot; title=&quot;https://github.com/ElectronNET/Electron.NET&quot; target=&quot;_blank&quot;&gt;Electron.NET&lt;/a&gt;! A new open source project which I developed in cooperation with my Microsoft MVP colleague and friend &lt;a href=&quot;https://twitter.com/robert0muehsig&quot; title=&quot;https://twitter.com/robert0muehsig&quot; target=&quot;_blank&quot;&gt;Robert Muehsig&lt;/a&gt;.&lt;/p&gt;

&lt;!-- more --&gt;

&lt;p&gt;As the name confirms, we developed an Electron derivation for .NET Core. This allows to develop Cross-Platform desktop applications with C# and ASP.NET Core. We haven´t reinvented the wheel. The runtime is based on Electron. So Electron.NET is build on an advanced and solid platform.&lt;/p&gt;

&lt;p&gt;This article shows on a plain sample how easy it is, to develop Cross-Platform desktop software with Electron.NET and ASP.NET. We will develop a MusicPlayer, which has access to the music list to play any song we want.&lt;/p&gt;

&lt;p&gt;Preperations for the start:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.nodejs.org&quot; title=&quot;www.nodejs.org&quot; target=&quot;_blank&quot;&gt;Node.js (v.8.x)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;The latest &lt;a href=&quot;https://www.microsoft.com/net/download/core&quot; title=&quot;https://www.microsoft.com/net/download/core&quot; target=&quot;_blank&quot;&gt;.NET Core SDK&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.visualstudio.com/downloads/&quot; title=&quot;https://www.visualstudio.com/downloads/&quot; target=&quot;_blank&quot;&gt;Visual Studio 2017&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;a-new-aspnet-core-2-project&quot;&gt;A new ASP.NET Core 2 project&lt;/h2&gt;
&lt;p&gt;First of all, we create a new ASP.NET Core Web Application. Then choose the empty template and make sure you got ASP.NET Core 2.0 selected.&lt;/p&gt;

&lt;figure&gt;
	&lt;a href=&quot;/images/05/01-new-asp.net-core-project.jpg&quot;&gt;&lt;img src=&quot;/images/05/01-new-asp.net-core-project.jpg&quot; alt=&quot;New ASP.NET Core Project&quot; /&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;figure&gt;
	&lt;a href=&quot;/images/05/02-empty-template.jpg&quot;&gt;&lt;img src=&quot;/images/05/02-empty-template.jpg&quot; alt=&quot;Empty Template&quot; /&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;p&gt;&lt;strong&gt;Picture 1 – Create a new ASP.NET Core 2 project&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next, we need to install MVC via NuGet Package Manager:&lt;br /&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;Install-Package Microsoft.AspNetCore.Mvc -Version 2.0.0&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once installed there is a little work to do, before we can start. We will need to add a little something to the &lt;strong&gt;Startup.cs&lt;/strong&gt;. At first we need to configure the app to use the MVC framework.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;ConfigureServices&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IServiceCollection&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;services&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;services&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddMvc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;In the next step we have to configure the app to use the MVC request execution pipline (routing), with a default route.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Configure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IApplicationBuilder&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IHostingEnvironment&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;env&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;UseMvc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;routes&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;routes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;MapRoute&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;default&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;{controller=Home}/{action=Index}/{id?}&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// ...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Now that the MVC framework has been added we can add a Controller and a View to the project. Therefore we add a new folder, which we call Controllers. Then, right click on it to add a new Controller.&lt;/p&gt;

&lt;figure&gt;
	&lt;a href=&quot;/images/05/03-new-controller.jpg&quot;&gt;&lt;img src=&quot;/images/05/03-new-controller.jpg&quot; alt=&quot;New Controller&quot; /&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;figure&gt;
	&lt;a href=&quot;/images/05/04-empty-controller.jpg&quot;&gt;&lt;img src=&quot;/images/05/04-empty-controller.jpg&quot; alt=&quot;Empty Controller&quot; /&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;figure&gt;
	&lt;a href=&quot;/images/05/05-controller-name.jpg&quot;&gt;&lt;img src=&quot;/images/05/05-controller-name.jpg&quot; alt=&quot;Controllername&quot; /&gt;&lt;/a&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Picture 2 – Add a new Controller&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The HomeController will be added with a default method called Index. To add a view we need to right click on View() and select AddView.&lt;/p&gt;

&lt;figure&gt;
	&lt;a href=&quot;/images/05/06-new-view.jpg&quot;&gt;&lt;img src=&quot;/images/05/06-new-view.jpg&quot; alt=&quot;New View&quot; /&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;figure&gt;
	&lt;a href=&quot;/images/05/07-default-view.jpg&quot;&gt;&lt;img src=&quot;/images/05/07-default-view.jpg&quot; alt=&quot;Viewname&quot; /&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;p&gt;&lt;strong&gt;Picture 3 – Add a new View&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A new views folder including the Index.cshtml has been created automatically. The ASP.NET MVC Core project is now ready to implement some logic.&lt;/p&gt;

&lt;h2 id=&quot;add-electronnet&quot;&gt;Add Electron.NET&lt;/h2&gt;
&lt;p&gt;There are just a few more things to do, so we can run the ASP.NET MVC Core 2 application with Electron.NET. Of course we´ll need to install &lt;a href=&quot;https://www.nuget.org/packages/ElectronNET.API/&quot; title=&quot;https://www.nuget.org/packages/ElectronNET.API/&quot; target=&quot;_blank&quot;&gt;Electron.NET API&lt;/a&gt; through the NuGet Package Manager:&lt;br /&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;PM&amp;gt; Install-Package ElectronNET.API&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;UseElectron&lt;/code&gt; WebHostBuilder-Extension will be added to &lt;strong&gt;Program.cs&lt;/strong&gt; then.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IWebHost&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;BuildWebHost&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;WebHost&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;CreateDefaultBuilder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;UseElectron&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;UseStartup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Startup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;()&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Build&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;That´s it! Now Electron.NET can be used in our project. So far, nothing would happen, if we would run the project now. The application would just run in the background. Because we do not want to develop any background processes, we´ll add some bootstrap code to &lt;strong&gt;Startup.cs&lt;/strong&gt;, so an MainWindow will appear. Additionally we want the security option to be disabled. This will allow us to get access to the music list.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Configure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IApplicationBuilder&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IHostingEnvironment&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;env&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;env&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;IsDevelopment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;UseDeveloperExceptionPage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;UseMvc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;routes&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;routes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;MapRoute&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;default&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;{controller=Home}/{action=Index}/{id?}&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

    &lt;span class=&quot;nf&quot;&gt;Bootstrap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Bootstrap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;options&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;BrowserWindowOptions&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;WebPreferences&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;WebPreferences&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;WebSecurity&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;false&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Electron&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WindowManager&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;CreateWindowAsync&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;access-to-the-file-system&quot;&gt;Access to the file system&lt;/h2&gt;
&lt;p&gt;We will need access to the file system within the &lt;strong&gt;HomeController&lt;/strong&gt; now. To do so, the Electron.NET API gives us the opportunity to detect the path of the current platform of the music list. With .NET Core we get access to the filenames within the list. We´ll pass the results to the view then.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;ElectronNET.API&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;ElectronNET.API.Entities&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;Microsoft.AspNetCore.Mvc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.Collections.Generic&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.IO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.Threading.Tasks&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;MyElectronMusicPlayer.Controllers&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HomeController&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Controller&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IActionResult&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;musicPath&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Electron&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;App&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;GetPathAsync&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PathName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;music&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mp3Files&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Directory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;GetFiles&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;musicPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;*.mp3&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SearchOption&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TopDirectoryOnly&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mp4Files&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Directory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;GetFiles&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;musicPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;*.mp4&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SearchOption&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TopDirectoryOnly&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;musicFiles&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;();&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;musicFiles&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddRange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mp3Files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;musicFiles&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddRange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mp4Files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;View&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;musicFiles&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;the-view&quot;&gt;The View&lt;/h2&gt;
&lt;p&gt;The view and functionality is easy and not that much spectacular in this example. So there will just be shown a list of the music files which will play by button click. To do this, the HTML5 audio class will be used.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-html&quot; data-lang=&quot;html&quot;&gt;@model List&lt;span class=&quot;nt&quot;&gt;&amp;lt;string&amp;gt;&lt;/span&gt;

&lt;span class=&quot;cp&quot;&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;

&lt;span class=&quot;nt&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;meta&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;viewport&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;content=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;width=device-width&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;title&amp;gt;&lt;/span&gt;My Electron Music Player&lt;span class=&quot;nt&quot;&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;meta&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;charset=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;utf-8&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;h3&amp;gt;&lt;/span&gt;My Music&lt;span class=&quot;nt&quot;&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
        @foreach (string musicFile in Model)
        {
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;li&amp;gt;&lt;/span&gt;
                 @System.IO.Path.GetFileNameWithoutExtension(musicFile)

                &lt;span class=&quot;nt&quot;&gt;&amp;lt;button&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;onclick=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;playMusic('@musicFile.Replace(@&quot;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;\&quot;,&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;&quot;/&quot;)')&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Play&lt;span class=&quot;nt&quot;&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        }
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;

        &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;playMusic&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;musicFile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;audio&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Audio&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`file:///&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;musicFile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;audio&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;play&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;start-of-the-electronnet-application&quot;&gt;Start of the Electron.NET Application&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&quot;https://www.nuget.org/packages/ElectronNET.CLI&quot; title=&quot;https://www.nuget.org/packages/ElectronNET.CLI&quot; target=&quot;_blank&quot;&gt;Electron.NET CLI&lt;/a&gt; is necessary to execute the Electron.NET application. Unfortunately, we need to install the CLI by adding a reference to &lt;code class=&quot;highlighter-rouge&quot;&gt;.csproj&lt;/code&gt; file instead of an installation via NuGet as usual.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-xml&quot; data-lang=&quot;xml&quot;&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;ItemGroup&amp;gt;&lt;/span&gt;
       &lt;span class=&quot;nt&quot;&gt;&amp;lt;DotNetCliToolReference&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;Include=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;ElectronNET.CLI&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;Version=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;*&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/ItemGroup&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Then run &lt;code class=&quot;highlighter-rouge&quot;&gt;dotnet restore&lt;/code&gt; in the console.&lt;/p&gt;

&lt;p&gt;If it´s a new Electron.NET project, it is necessary to run &lt;code class=&quot;highlighter-rouge&quot;&gt;dotnet electronize init&lt;/code&gt; once. For that there will be a &lt;code class=&quot;highlighter-rouge&quot;&gt;electron.manifest.json&lt;/code&gt; file generated an a new debugging profile will be provided.&lt;/p&gt;

&lt;p&gt;The command &lt;code class=&quot;highlighter-rouge&quot;&gt;dotnet electronize start&lt;/code&gt; will start the ASP.NET MVC Core 2 application as a desktop software.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;blockquote&gt;
    &lt;p&gt;&lt;strong&gt;Important!&lt;/strong&gt; The first start may take a while. We are working on a solution to speed this up.&lt;/p&gt;
  &lt;/blockquote&gt;
&lt;/blockquote&gt;

&lt;figure&gt;
	&lt;a href=&quot;/images/05/08-Electron.NET-Music-Player.jpg&quot;&gt;&lt;img src=&quot;/images/05/08-Electron.NET-Music-Player.jpg&quot; alt=&quot;Electron.NET Music Player&quot; /&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;p&gt;&lt;strong&gt;Picture 4 – The Electron MusicPlayer application&lt;/strong&gt;&lt;/p&gt;

&lt;h2 id=&quot;building-the-application&quot;&gt;Building the application&lt;/h2&gt;
&lt;p&gt;The Electron.NET CLI also makes it possible to build an executable application for Windows, Mac and Linux. Every platform does this with the &lt;code class=&quot;highlighter-rouge&quot;&gt;dotnet electronize build&lt;/code&gt; command:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;dotnet electronize build win&lt;/code&gt;&lt;br /&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;dotnet electronize build osx&lt;/code&gt;&lt;br /&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;dotnet electronize build linux&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;blockquote&gt;
    &lt;p&gt;&lt;strong&gt;Important!&lt;/strong&gt; A Mac or Linux device is required to build Mac applications.&lt;/p&gt;
  &lt;/blockquote&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;
&lt;p&gt;We´ve seen in this sample, how easy it is to create a desktop software using ASP.NET MVC Core 2. We get access to the files by using C# and send those information to the MVC view, which is actually not possible through a Web-Browser.&lt;/p&gt;

&lt;p&gt;You´ll find additional examples in the API demo app. You can try to access an OpenFile dialog so the sample application can read other files as well, if you want to. And maybe there could be a little shortcut to select songs randomly. Just as a little extra 😊 Leave a comment below if managed it.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/ElectronNET/electron.net-musicplayer-sample&quot; title=&quot;https://github.com/ElectronNET/electron.net-musicplayer-sample&quot; target=&quot;_blank&quot;&gt;Here´s the MusicPlayer on GitHub&lt;/a&gt;  &lt;br /&gt;
&lt;a href=&quot;https://github.com/ElectronNET/electron.net-api-demos&quot; title=&quot;https://github.com/ElectronNET/electron.net-api-demos&quot; target=&quot;_blank&quot;&gt;Here you´ll find the Electron.NET API Demo App on GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How do you like Electron.NET? I´m excited about your feedback in the comments.&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;http://www.cross-platform-blog.com/electron.net/electron.net-musicplayer-app-with-asp.net-core/&quot;&gt;Electron.NET – Create a minimal MusicPlayer App with ASP.NET Core 2 for the Desktop&lt;/a&gt; was originally published by Gregor Biswanger at &lt;a href=&quot;http://www.cross-platform-blog.com&quot;&gt;Cross-Platform-Blog.com&lt;/a&gt; on October 27, 2017.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Interview with webpack founder Tobias Koppers]]></title>
 <link rel="alternate" type="text/html" href="http://www.cross-platform-blog.com/tools/interview-with-webpack-author-tobias-koppers/" />
  <id>http://www.cross-platform-blog.com/tools/interview-with-webpack-author-tobias-koppers</id>
  <updated>2017-03-04T00:00:00-00:00</updated>
  <published>2017-04-03T00:00:00+02:00</published>
  
  <author>
    <name>Gregor Biswanger</name>
    <uri>http://www.cross-platform-blog.com</uri>
    <email>gregor.biswanger@web-enliven.de</email>
  </author>
  <content type="html">
    &lt;p&gt;Tobias Koppers is a freelance software developer and consultant from Nuremberg. He became famous as author of webpack, which is used by millions of developers worldwide. His focus is on JavaScript development and open source projects. I had him in an exclusive interview, which I would not want to keep away from you. Have fun while reading it.&lt;/p&gt;

&lt;!-- more --&gt;

&lt;p&gt;&lt;strong&gt;Gregor: Hello Tobias, the whole JavaScript world talks about webpack. Even Google is based on it and has integrated it directly into the Angular CLI. I am also particularly proud of the fact that webpack comes from Nuremberg, so close to my hometown Ingolstadt (Germany). Tell us the story, how you came up with the idea and how webpack could spread so quickly.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tobias:&lt;/strong&gt; Hi Gregor. In fact, Google was also involved in the development, if only indirectly. Before I was addicted to JavaScript, I also worked with Java. There is a tool from Google that allows to develop a client-side web application in Java: Google Web Toolkit (GWT). This is a Java-to-JavaScript compiler for SPAs, which is also based on some Google applications.&lt;/p&gt;

&lt;p&gt;At the GWT there was one feature which I was totally into: Code Splitting. This allows, among other things, rarely used code to be loaded later. This feature is especially important for large applications to keep the initial load time small. I missed this feature in existing JavaScript-Tooling (2012) and this was when the idea of webpack was born.&lt;/p&gt;

&lt;p&gt;That means, webpack was created with the focus on code splitting, and in my opinion that was the reason why it was so common. With the growing size of web applications and the increased use of mobile devices (with weak network connectivity), they have grown the relevance of code splitting over time. Otherwise the desired performance is difficult to implement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gregor: Many compare webpack with task tools such as NPM scripts, Grunt and Gulp. Some have really found their replacement with webpack. I will use NPM scripts and webpack in future on. What’s your opinion on this and do you use a task tool in addition to webpack?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tobias:&lt;/strong&gt; NPM scripts are enough for me. In fact, it is not really correct to call webpack as a substitute for Grunt / Gulp. Grunt and Gulp belong to another category of tools like webpack. Grunt, Gulp and NPM scripts are task runner.&lt;/p&gt;

&lt;p&gt;Webpack is a Module Bundler. These are tools with different objectives. But it is true that webpack simplifies the necessary “tasks” to build a web application so far that it is possible to use an overkill TaskRunner like Grunt and Gulp and NPM scripts are sufficient. NPM is the replacement for Grunt and Gulp.&lt;/p&gt;

&lt;p&gt;However, task runner still have their own reasoning for other tasks besides the pure building of the web application: deployment, linting, version management, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gregor: With my JavaScript trainings, my participants are telling me over and over again, how difficult it is to start with webpack. Did you get similar feedback already? If so, do you already have ideas on how to improve that?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tobias:&lt;/strong&gt; Yes, indeed, this feedback comes. However, many users also say that once it has “clicked”, it is actually quite simple to use. Anyone who can “web” even says that it is easier than the previous tools.&lt;/p&gt;

&lt;p&gt;I believe this feedback is due to the fact that the concepts of webpack differ significantly from the concepts of other tools. Especially when migrating from Grunt / Gulp to webpack. Task runner have a more imperative configuration, that is describing the steps to be performed by the task runner. Webpack, on the other hand, has a declarative configuration, that means, it does not describe the steps to be executed by webpack, but only describes the way in which these steps are to be executed or how the result has to look.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gregor: What’s on your agenda? What features are planned for the next webpack version?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tobias:&lt;/strong&gt; That’s not quite clear yet. There are so many things that are possible. Just to mention a few exciting points:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Scope Hoisting: small and more powerful way to connect the modules&lt;/li&gt;
  &lt;li&gt;WebAssembly: Support for binary code in the WebApp&lt;/li&gt;
  &lt;li&gt;Persistenter cache: Faster initial compilation&lt;/li&gt;
  &lt;li&gt;CSS (and HTML) as first-class citizen: More support for stylesheets (and HTML)&lt;/li&gt;
  &lt;li&gt;And many exciting little things&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The users and sponsors decide in which order they will be targeted. We have a voting page, where you can vote for the next points. Everyone gets an influence every day and sponsors and contributors get golden points of influence for donations and contributions. This happens from the motivation of sponsors and contributors, because they wanted to give something back. In addition, it is of course interesting what users want the most.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gregor: Can you give us a top best practice tip on webpack?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tobias:&lt;/strong&gt; Use On-Demand-Loading. It is super easy to use and it works out incredibly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gregor: What are your personal goals? Will we all soon read, that you’re going to work at Google in Mountain View? ;)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tobias:&lt;/strong&gt; I don’t think so. I will be working as a freelancer soon. I will try to work as much as possible on open source and finance the whole thing through donations. Since donations are usually not enough, I will finance the rest through commissioning or consulting. I’m already curious how this works. Maybe there is a sponsor for me, who will finance a few additional weeks Open Source (hey Google ;)).&lt;/p&gt;

&lt;p&gt;The effort to maintain an open source project is often underestimated. Currently, Code Reviews and Issues take 80% of my time. I neither have enough time to write code myself, nor to refactor. I even have to leave pull requests behind for a while. I need to find the time to look at them in detail. This is not really motivating the contributor of course. I think this will change, as soon as I work on webpack full time. Hopefully I have more time to write more code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gregor: Thank you very much for taking the time for the interview! Thanks also for webpack, which supports us as JavaScript developers extremely. I love your tool!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tobias:&lt;/strong&gt; You’re welcome. My thanks goes back to the community. Webpack is not “my” tool, it is designed by more than 500 contributors. Webpacks success is also because of its great ecosystem.&lt;/p&gt;


    &lt;p&gt;&lt;a href=&quot;http://www.cross-platform-blog.com/tools/interview-with-webpack-author-tobias-koppers/&quot;&gt;Interview with webpack founder Tobias Koppers&lt;/a&gt; was originally published by Gregor Biswanger at &lt;a href=&quot;http://www.cross-platform-blog.com&quot;&gt;Cross-Platform-Blog.com&lt;/a&gt; on April 03, 2017.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[JavaScript Coding Dojo: The DictionaryReplacer Kata]]></title>
 <link rel="alternate" type="text/html" href="http://www.cross-platform-blog.com/coding-dojo-katas/javascript-coding-dojo-dictionaryreplacer-kata/" />
  <id>http://www.cross-platform-blog.com/coding-dojo-katas/javascript-coding-dojo-dictionaryreplacer-kata</id>
  <updated>2017-03-02T00:00:00-00:00</updated>
  <published>2017-02-03T00:00:00+01:00</published>
  
  <author>
    <name>Gregor Biswanger</name>
    <uri>http://www.cross-platform-blog.com</uri>
    <email>gregor.biswanger@web-enliven.de</email>
  </author>
  <content type="html">
    &lt;p&gt;A dojo is the exercise room of Japanese martial arts. The exercises itself are called kata. The coding dojo is about mastering an exercise (kata). According to the motto “Learning by doing”. The cross-platform blog will now regularly publish JavaScript Katas.&lt;/p&gt;

&lt;h2 id=&quot;the-dictionaryreplacer-kata&quot;&gt;The DictionaryReplacer Kata&lt;/h2&gt;
&lt;p&gt;This kata is about making a simple string replacer. It is inspired by Corey Haines Lightning talk about practicing. Create a method that takes a string and a dictionary, and replaces every key in the dictionary pre and suffixed with a dollar sign, with the corresponding value from the Dictionary.&lt;/p&gt;

&lt;!-- more --&gt;

&lt;p&gt;&lt;strong&gt;Tests:&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;input:&lt;/strong&gt; “”, &lt;strong&gt;dictionary:&lt;/strong&gt; empty, &lt;strong&gt;output:&lt;/strong&gt; “”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;input:&lt;/strong&gt; “$temp$”, &lt;strong&gt;dictionary:&lt;/strong&gt; [“temp”, “temporary”], &lt;strong&gt;output:&lt;/strong&gt; “temporary”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;input:&lt;/strong&gt; “$temp$ here comes the name $name$”, &lt;strong&gt;dictionary:&lt;/strong&gt; [“temp”, “temporary”] [“name”, “John Doe”], &lt;strong&gt;output:&lt;/strong&gt; “temporary here comes the name John Doe”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Difficulty:&lt;/strong&gt; Simple&lt;br /&gt;
&lt;strong&gt;Duration:&lt;/strong&gt; Ca. 5-20 Minutes&lt;br /&gt;
&lt;strong&gt;Source:&lt;/strong&gt; &lt;a href=&quot;http://codingdojo.org/kata/DictionaryReplacer/&quot; title=&quot;The DictionaryReplacer Kata&quot; target=&quot;_blank&quot;&gt;http://codingdojo.org/kata/DictionaryReplacer/&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;preperations-for-the-start&quot;&gt;Preperations for the start&lt;/h2&gt;
&lt;p&gt;The following is required for the project:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.nodejs.org&quot; title=&quot;www.nodejs.org&quot; target=&quot;_blank&quot;&gt;Node.js&lt;/a&gt; (runs on Windows, Mac and Linux)&lt;/li&gt;
  &lt;li&gt;TypeScript&lt;br /&gt;
type &lt;code class=&quot;highlighter-rouge&quot;&gt;npm install typescript –g&lt;/code&gt; in the terminal&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://code.visualstudio.com&quot; title=&quot;http://code.visualstudio.com&quot; target=&quot;_blank&quot;&gt;Visual Studio Code&lt;/a&gt; (runs on Windows, Mac and Linux)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There has already been deposited a complete exercise project on GitHub for you:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;git clone https://github.com/GregorBiswanger/KataDictionaryReplacer.git&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then install all necessary modules within the project with &lt;code class=&quot;highlighter-rouge&quot;&gt;npm install&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;You have never worked with TypeSript before? Don`t worry! TypeScript == JavaScript, and you can use your existing JavaScript knowledge without problems. The advantages? Go and find it out by yourself in the code exercise. ;) A significant difference is that the file ending is * .TS. The TypeScript created javascript and source map files are hidden for this exercise. This provides a better overview. In the file system, however, these exist.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;the-start&quot;&gt;The start&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;Open the project with Visual Studio Code&lt;/li&gt;
  &lt;li&gt;Start the TypeScript compiler with the key combination &lt;code class=&quot;highlighter-rouge&quot;&gt;[ctrl] + [shift] + [b]&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;At the terminal, write &lt;code class=&quot;highlighter-rouge&quot;&gt;npm test&lt;/code&gt; within your project&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now the testrunner Jasmine is running. It notices file changes automatically. If you have a second monitor, there is the ideal place for the terminal. This allows you to observe the current status during development.&lt;/p&gt;

&lt;figure&gt;
	&lt;a href=&quot;/images/04/vscode-npm-test.jpg&quot;&gt;&lt;img src=&quot;/images/04/vscode-npm-test.jpg&quot; alt=&quot;npm start&quot; /&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;the-process&quot;&gt;The process&lt;/h2&gt;
&lt;p&gt;Important with Coding Dojos is, to solve every task step by step. This principle is not easy for many developers. But exactly this is, what coding dojos are teaching us.&lt;/p&gt;

&lt;p&gt;Which tasks have to be performed step by step can be found in the &lt;code class=&quot;highlighter-rouge&quot;&gt;spec&lt;/code&gt; directory. The actual programming takes place in the &lt;code class=&quot;highlighter-rouge&quot;&gt;src&lt;/code&gt; folder.&lt;/p&gt;

&lt;h2 id=&quot;debugging&quot;&gt;Debugging&lt;/h2&gt;
&lt;p&gt;The project already has all the necessary Visual Studio Code settings, so you can easily debug within the tests or your own code. Simply set the breakpoint with the &lt;code class=&quot;highlighter-rouge&quot;&gt;[F9]&lt;/code&gt;-key and start the debugging with &lt;code class=&quot;highlighter-rouge&quot;&gt;[F5]&lt;/code&gt;.&lt;/p&gt;

&lt;figure&gt;
	&lt;a href=&quot;/images/04/vscode-jasmine-debugging.jpg&quot;&gt;&lt;img src=&quot;/images/04/vscode-jasmine-debugging.jpg&quot; alt=&quot;Unit Test Debugging&quot; /&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;rules&quot;&gt;Rules&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Solve the kata until all tests are green&lt;/li&gt;
  &lt;li&gt;Then copy your solution here on jsfiddle.net:&lt;br /&gt;
  &lt;strong&gt;&lt;a href=&quot;https://jsfiddle.net/GregorBiswanger/n6zm9wz7/&quot; title=&quot;jsfiddle.net&quot; target=&quot;_blank&quot;&gt;https://jsfiddle.net/GregorBiswanger/n6zm9wz7/&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Click on the “Update” button in the upper left corner and comment on your link here at this blog post&lt;/li&gt;
  &lt;li&gt;Not till then, you are allowed to compare your solution with already commented solutions&lt;/li&gt;
&lt;/ul&gt;

&lt;figure&gt;
	&lt;a href=&quot;/images/04/jsfiddle-typescript-jasmine.jpg&quot;&gt;&lt;img src=&quot;/images/04/jsfiddle-typescript-jasmine.jpg&quot; alt=&quot;jsfiddle kata mit typescript und jasmine&quot; /&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;lets-get-ready-to-rumble&quot;&gt;Let’s get ready to rumble!&lt;/h2&gt;
&lt;p&gt;With my JavaScript Workshops I always like to do Coding Dojos with my participants. I love to evaluate the different solutions afterwards. I`m excited about how you will solve the task. And now: Let’s get ready to rumble!&lt;/p&gt;


    &lt;p&gt;&lt;a href=&quot;http://www.cross-platform-blog.com/coding-dojo-katas/javascript-coding-dojo-dictionaryreplacer-kata/&quot;&gt;JavaScript Coding Dojo: The DictionaryReplacer Kata&lt;/a&gt; was originally published by Gregor Biswanger at &lt;a href=&quot;http://www.cross-platform-blog.com&quot;&gt;Cross-Platform-Blog.com&lt;/a&gt; on February 03, 2017.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Node.js: A REST Web-API with Express.js and TypeScript]]></title>
 <link rel="alternate" type="text/html" href="http://www.cross-platform-blog.com/nodejs/typescript/nodejs-a-rest-web-api-expressjs-with-typescript/" />
  <id>http://www.cross-platform-blog.com/nodejs/typescript/nodejs-a-rest-web-api-expressjs-with-typescript</id>
  <updated>2017-30-01T00:00:00-00:00</updated>
  <published>2017-01-30T00:00:00+01:00</published>
  
  <author>
    <name>Gregor Biswanger</name>
    <uri>http://www.cross-platform-blog.com</uri>
    <email>gregor.biswanger@web-enliven.de</email>
  </author>
  <content type="html">
    &lt;p&gt;There is one Web-Application Framework, which has been strongly enforced with Node.js: Express.js. It has been inspired by the Sinatra-Framework, known of the Ruby world. It extends the Node.js Build-In modul &lt;code class=&quot;highlighter-rouge&quot;&gt;http&lt;/code&gt;, so developing a modern web-app will be simplified:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Comparable to the Microsoft Web-API (just better :))&lt;/li&gt;
  &lt;li&gt;Communication with REST (HTTP) is norm&lt;/li&gt;
  &lt;li&gt;Request/Response-Handling&lt;/li&gt;
  &lt;li&gt;Routing&lt;/li&gt;
  &lt;li&gt;View Templating&lt;/li&gt;
  &lt;li&gt;Session Support&lt;/li&gt;
  &lt;li&gt;Static Files Support&lt;/li&gt;
  &lt;li&gt;Middleware
    &lt;ul&gt;
      &lt;li&gt;e.g. functions, which are able to log between request and response (Logger etc.)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;and many more…&lt;br /&gt;
&lt;!-- more --&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;the-installation&quot;&gt;The installation&lt;/h2&gt;
&lt;p&gt;At first we need to create a new Node.js project with a TypeScript compiler configuration and the appropriated Visual Studio Code build and debugging configuration. Those steps have already been explained in detail in the following article:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;http://www.cross-platform-blog.com/tools/nodejs/typescript/visual-studio-code-nodejs-with-typescript-and-debugging/&quot; title=&quot;Visual Studio Code: Node.js with TypeScript and Debugging&quot; target=&quot;_blank&quot;&gt;Visual Studio Code: Node.js with TypeScript and Debugging&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In addition to that, Express.js and the associated TypeScript declaration is needed. To include them, you just need to write following in the terminal within the project:&lt;br /&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;npm install express –save&lt;/code&gt;&lt;br /&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;npm install @types/express –save-dev&lt;/code&gt;&lt;/p&gt;

&lt;h2 id=&quot;the-first-expressjs-hello-world&quot;&gt;The first Express.js „Hello World“&lt;/h2&gt;
&lt;p&gt;We create a new &lt;strong&gt;index.ts&lt;/strong&gt; file or replace the existing file with this code:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;express&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'express'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;express&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'/'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'Hello World'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;listen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The code is very similar from the usual “Hello World” example for Node.js. The differences: Express.js creates a web server automatically in the background with the &lt;code class=&quot;highlighter-rouge&quot;&gt;listen&lt;/code&gt; function. The query for REST is given explicitly, like in this example with &lt;code class=&quot;highlighter-rouge&quot;&gt;get&lt;/code&gt;. Routing is then set with a string value. When the request is processed, an anonymous function is executed as usual, but no stream has to be explicitly terminated here. This is why Express.js takes care of itself automatically.&lt;/p&gt;

&lt;h2 id=&quot;the-get-function-with-parameter&quot;&gt;The GET function with parameter&lt;/h2&gt;
&lt;p&gt;A REST GET action is stored using the &lt;code class=&quot;highlighter-rouge&quot;&gt;get&lt;/code&gt; function. Routing is defined by string and parameters are additionally marked with a colon and variable names. As the following example shows:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'/api/sayhello/:name'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;isNaN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;response&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;400&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'No string as name'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
            &lt;span class=&quot;s2&quot;&gt;&quot;message&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;In Visual Studio code, start the TypeScript compiler &lt;code class=&quot;highlighter-rouge&quot;&gt;[ctrl] + [shift] + [b]&lt;/code&gt; if it is not already running. Next, execute the application with &lt;code class=&quot;highlighter-rouge&quot;&gt;[F5]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Then type &lt;strong&gt;http://localhost:3000/api/sayhello/John&lt;/strong&gt; in the browser. The Web service should now return the following JSON value:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot; data-lang=&quot;json&quot;&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;message&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;John&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The following return functions are possible with the Get function:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;render&lt;/code&gt; for HTML content using View Engine&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;send&lt;/code&gt; for text content&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;json&lt;/code&gt; for JSON content&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;redirect&lt;/code&gt; for forwarding&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;queries&quot;&gt;Queries&lt;/h2&gt;
&lt;p&gt;Ordinary query parameters can also be queried. These are located under &lt;code class=&quot;highlighter-rouge&quot;&gt;request.query.PARAMETERNAME&lt;/code&gt;. Additional routing is not required.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'/api/sayhello/'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;isNaN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;response&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;400&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'No string as name'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Next, execute the application with &lt;code class=&quot;highlighter-rouge&quot;&gt;[F5]&lt;/code&gt;. Then type &lt;strong&gt;http://localhost:3000/api/sayhello?name=NodeJS&lt;/strong&gt; in the browser.&lt;/p&gt;

&lt;h2 id=&quot;the-post-action&quot;&gt;The post action&lt;/h2&gt;
&lt;p&gt;Provide a post action by a &lt;code class=&quot;highlighter-rouge&quot;&gt;post&lt;/code&gt; function. In order to process regular Form-Submit POST requests, however, two additional packages are required:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;npm install body-parser multer --save&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;These are relevant for parsing &lt;em&gt;multipart/form-data&lt;/em&gt; and &lt;em&gt;application/x-www-form-urlencoded&lt;/em&gt;. As a single-middleware, &lt;code class=&quot;highlighter-rouge&quot;&gt;upload.array()&lt;/code&gt; is also included in the post function. Forms sent data are queried through &lt;code class=&quot;highlighter-rouge&quot;&gt;request.body.VARIABLENAME&lt;/code&gt;.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;express&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'express'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;express&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// For POST-Support&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;bodyParser&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'body-parser'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;multer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'multer'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;upload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;multer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;use&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bodyParser&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;urlencoded&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;extended&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}));&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'/api/sayHello'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;upload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;isNaN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;response&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;400&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'No string as name'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'Hello '&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'POST request to homepage'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;listen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Tools such as &lt;a href=&quot;https://www.getpostman.com&quot; title=&quot;Postman&quot; target=&quot;_blank&quot;&gt;Postman&lt;/a&gt; are suitable for testing. At Postman select “POST” first and type in the URL field &lt;strong&gt;http://localhost:3000/api/sayhello/&lt;/strong&gt;. The following query comes directly below:&lt;/p&gt;

&lt;figure&gt;
	&lt;a href=&quot;/images/03/postman-post.jpg&quot;&gt;&lt;img src=&quot;/images/03/postman-post.jpg&quot; alt=&quot;Post request with Postman&quot; /&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;p&gt;Now click on the next button and directly below the response data will appear. In Visual Studio Code you can debug the post request.&lt;/p&gt;

&lt;figure&gt;
	&lt;a href=&quot;/images/03/vscode-expressjs-debugging.jpg&quot;&gt;&lt;img src=&quot;/images/03/vscode-expressjs-debugging.jpg&quot; alt=&quot;Debug the post request with Visual Studio Code&quot; /&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;With Express.js you can quickly and easily provide web services and much more. In other articles I will go even deeper and further into this great Web Application Framework.
The source code for the examples is based on GitHub:&lt;/p&gt;

&lt;div&gt;&lt;a href=&quot;https://github.com/GregorBiswanger/VSCodeExpressjsTypeScriptSample&quot; target=&quot;_blank&quot; class=&quot;btn btn-success&quot;&gt;Code on GitHub&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;How do you like Express.js? I’m looking forward to read your opinion in the comments.&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;http://www.cross-platform-blog.com/nodejs/typescript/nodejs-a-rest-web-api-expressjs-with-typescript/&quot;&gt;Node.js: A REST Web-API with Express.js and TypeScript&lt;/a&gt; was originally published by Gregor Biswanger at &lt;a href=&quot;http://www.cross-platform-blog.com&quot;&gt;Cross-Platform-Blog.com&lt;/a&gt; on January 30, 2017.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Visual Studio Code: Node.js with TypeScript and Debugging]]></title>
 <link rel="alternate" type="text/html" href="http://www.cross-platform-blog.com/tools/nodejs/typescript/visual-studio-code-nodejs-with-typescript-and-debugging/" />
  <id>http://www.cross-platform-blog.com/tools/nodejs/typescript/visual-studio-code-nodejs-with-typescript-and-debugging</id>
  <updated>2017-27-01T00:00:00-00:00</updated>
  <published>2017-01-27T00:00:00+01:00</published>
  
  <author>
    <name>Gregor Biswanger</name>
    <uri>http://www.cross-platform-blog.com</uri>
    <email>gregor.biswanger@web-enliven.de</email>
  </author>
  <content type="html">
    &lt;p&gt;Visual Studio Code is a free code editor of Microsoft with an excellent TypeScript and Node.js development support. This blog post describes how easy it is to create a new Node.js project with TypeScript support. And at the end, we will also debug a small “Hello World” example.&lt;br /&gt;
  &lt;!-- more --&gt;&lt;/p&gt;

&lt;p&gt;The example in this article provides to setup the following:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.nodejs.org&quot; title=&quot;www.nodejs.org&quot; target=&quot;_blank&quot;&gt;Node.js - http://www.nodejs.org&lt;/a&gt; (runs on Windows, Mac and Linux)&lt;/li&gt;
  &lt;li&gt;TypeScript&lt;br /&gt;
type &lt;code class=&quot;highlighter-rouge&quot;&gt;npm install typescript –g&lt;/code&gt; in the terminal&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://code.visualstudio.com&quot; title=&quot;http://code.visualstudio.com&quot; target=&quot;_blank&quot;&gt;Visual Studio Code - http://code.visualstudio.com&lt;/a&gt; (runs on Windows, Mac and Linux)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;a-new-project&quot;&gt;A new project&lt;/h2&gt;
&lt;p&gt;To create a new project, the only thing we need is a new folder in our file explorer. Afterwards, we open the created folder in Visual Studio Code &lt;code class=&quot;highlighter-rouge&quot;&gt;File | Open Folder&lt;/code&gt;. As project file the packages.json file is needed. To include it, we just have to write &lt;code class=&quot;highlighter-rouge&quot;&gt;npm init –y&lt;/code&gt; in the terminal. You can open the integrated terminal in Visual Studio Code using the keyboard shortcut &lt;code class=&quot;highlighter-rouge&quot;&gt;[Ctrl] + [`]&lt;/code&gt;.&lt;/p&gt;

&lt;figure&gt;
	&lt;a href=&quot;/images/02/vscode-npm-init.jpg&quot;&gt;&lt;img src=&quot;/images/02/vscode-npm-init.jpg&quot; alt=&quot;Visual Studio Code&quot; /&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;install-nodejs-declaration-files&quot;&gt;Install Node.js declaration files&lt;/h2&gt;
&lt;p&gt;To ensure that Visual Studio Code can solve Node.js features within IntelliSense, the TypeScript declaration files for Node.js are required. They will be installed with the node package manager (npm) since TypeScript 2.  The command &lt;code class=&quot;highlighter-rouge&quot;&gt;npm install @types/node --save-dev&lt;/code&gt; will have it done. To install other packages like jQuery for example, you would have to call &lt;code class=&quot;highlighter-rouge&quot;&gt;npm install @types/jquery --save-dev&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;typescript-compiler-configuration&quot;&gt;TypeScript compiler configuration&lt;/h2&gt;
&lt;p&gt;For a proper Node.js support with TypeScript, a compiler configuration file is absolutely necessary. It will be created as &lt;code class=&quot;highlighter-rouge&quot;&gt;tsconfig.json&lt;/code&gt; in the root directory. Thanks to the JSON IntelliSense feature of Visual Studio Code, which automatically provides an autocomplete on the basis of the filename. 
So you just need to write the first curly braces and IntelliSense will autocomplete it with the shortcut &lt;code class=&quot;highlighter-rouge&quot;&gt;[Ctrl] + [.]&lt;/code&gt;. The IntelliSense support only works with an existing internet connection. In this case you need write the following compiler configuration:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot; data-lang=&quot;json&quot;&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;compilerOptions&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;module&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;commonjs&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;sourceMap&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;watch&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;&lt;strong&gt;Module&lt;/strong&gt;: In a typical web application, the browser obtains the JavaScript files via the Script tag. With Node.js, the JavaScript code will be executed irrespective of the website. This is the reason, the modul system CommonJS has been developed. It allows to load JavaScript files within the JavaScript code. Because of that, TypeScript needs to know which modul system is used, so the “import” and “export” code will be generated automatically.&lt;br /&gt;
&lt;strong&gt;Source Map&lt;/strong&gt;: As the name suggests, debugger-service maps will be generated here. They support the debugger to solve a code area of the TypeScript file to the generated JavaScript file. So it is possible to debug right within the TypeScript file.&lt;br /&gt;
&lt;strong&gt;Watch&lt;/strong&gt;: The watch option helps to prevent to start the TypeScript compiler before each debugging. It monitors all  TypeScript files for changes. If a file changes, the compiler is automatically activated. So the compiler has to be started only once.&lt;/p&gt;

&lt;h2 id=&quot;the-first-nodejs-hello-world&quot;&gt;The first Node.js „Hello World“&lt;/h2&gt;
&lt;p&gt;Now we create an &lt;strong&gt;index.ts&lt;/strong&gt; file. The following code is required for a “Hello World” example:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;http&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'http'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;http&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createServer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'Hello from Node.js!'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;listen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The first line begins with a TypeScript-specific keyword &lt;code class=&quot;highlighter-rouge&quot;&gt;import&lt;/code&gt;. Thus, TypeScript knows that there must be a declaration for this module. If there is no declaration file or a TypeScript code in the project, &lt;code class=&quot;highlighter-rouge&quot;&gt;let&lt;/code&gt; is written as usual. Then we access a Node.js build-in module called &lt;code class=&quot;highlighter-rouge&quot;&gt;http&lt;/code&gt;. The first line is comparable to a &lt;code class=&quot;highlighter-rouge&quot;&gt;using&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;import&lt;/code&gt; or &lt;code class=&quot;highlighter-rouge&quot;&gt;include&lt;/code&gt; from other high-level languages.&lt;/p&gt;

&lt;p&gt;From line 3, a Web server is already being created. When calling, the anonymous function is triggered and a streaming to the client is active. Here we get all client request information with the &lt;code class=&quot;highlighter-rouge&quot;&gt;request&lt;/code&gt; parameter. We can use the &lt;code class=&quot;highlighter-rouge&quot;&gt;response&lt;/code&gt; parameter to append data to the current stream. The simple &lt;code class=&quot;highlighter-rouge&quot;&gt;write&lt;/code&gt; function was used to send a simple string value. To terminate the current stream, the &lt;code class=&quot;highlighter-rouge&quot;&gt;end&lt;/code&gt; function is required.
With the &lt;code class=&quot;highlighter-rouge&quot;&gt;listen&lt;/code&gt; function, the current web server is activated for the defined port. That’s it!&lt;/p&gt;

&lt;h2 id=&quot;start-the-typescript-compiler-with-visual-studio-code&quot;&gt;Start the TypeScript compiler with Visual Studio Code&lt;/h2&gt;
&lt;p&gt;The TypeScript file was written, but a JavaScript file is needed to run it. The key combination &lt;code class=&quot;highlighter-rouge&quot;&gt;[Ctrl] + [Shift] + [b]&lt;/code&gt; prompts Visual Studio Code to build the project. Alternatively, you can open the command line with &lt;code class=&quot;highlighter-rouge&quot;&gt;[F1]&lt;/code&gt; and type &lt;code class=&quot;highlighter-rouge&quot;&gt;Build&lt;/code&gt;. Now Visual Studio Code does not know what exactly it should do. So it will ask you, what exactly you want. We choose &lt;code class=&quot;highlighter-rouge&quot;&gt;TypeScript - tsconfig.json&lt;/code&gt; here.&lt;/p&gt;

&lt;figure&gt;
	&lt;a href=&quot;/images/02/vscode-no-task-runner-configured.jpg&quot;&gt;&lt;img src=&quot;/images/02/vscode-no-task-runner-configured.jpg&quot; alt=&quot;Visual Studio Code - No task runner configured&quot; /&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;figure&gt;
	&lt;a href=&quot;/images/02/vscode-select-a-task-runner-typescript.jpg&quot;&gt;&lt;img src=&quot;/images/02/vscode-select-a-task-runner-typescript.jpg&quot; alt=&quot;Visual Studio Code - Select a task runner&quot; /&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;p&gt;A new directory is created with &lt;code class=&quot;highlighter-rouge&quot;&gt;.vscode&lt;/code&gt; and a tasks.json file is created. The pleasant thing about this template is that all relevant settings are already stored. So we can close this file and call the build process again with &lt;code class=&quot;highlighter-rouge&quot;&gt;[Ctrl] + [Shift] + [b]&lt;/code&gt;. Left below we can see a rotating character and in File Explorer we can see two new files for our TypeScript file. One is the generated JavaScript file and the other is the  SourceMap file which is required for debugging.&lt;/p&gt;

&lt;h2 id=&quot;debug-the-nodejs-application&quot;&gt;Debug the Node.js application&lt;/h2&gt;
&lt;p&gt;There are different ways to run the application. One way is to start from the terminal using &lt;code class=&quot;highlighter-rouge&quot;&gt;node index.js&lt;/code&gt;, regardless of Visual Studio Code. The only bad thing is, we have no debugging comfort here. Therefore we use the second option: We press the &lt;code class=&quot;highlighter-rouge&quot;&gt;[F5]&lt;/code&gt; key within Visual Studio Code to debug. Again, Visual Studio Code does not know what exactly it should run. We select &lt;code class=&quot;highlighter-rouge&quot;&gt;node.js&lt;/code&gt;.&lt;/p&gt;

&lt;figure&gt;
	&lt;a href=&quot;/images/02/vscode-select-environment-nodejs.jpg&quot;&gt;&lt;img src=&quot;/images/02/vscode-select-environment-nodejs.jpg&quot; alt=&quot;Visual Studio Code - Select environment node.js&quot; /&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;p&gt;A further JSON file is created in the &lt;code class=&quot;highlighter-rouge&quot;&gt;.vscode&lt;/code&gt; directory. It is important to note that the JavaScript file name corresponds to what we have created and that the option SourceMaps is activated. Otherwise, we can only debug within the JavaScript file. Then press the &lt;code class=&quot;highlighter-rouge&quot;&gt;[F5]&lt;/code&gt; button again. The server has now been started. If we press the &lt;code class=&quot;highlighter-rouge&quot;&gt;[F9]&lt;/code&gt; key in the &lt;code class=&quot;highlighter-rouge&quot;&gt;response.write&lt;/code&gt; line, or alternatively next to the line number, we get a red breakpoint. Now go to the browser and call your web server with http: // localhost: 3000. Visual Studio Code then stops at the breakpoint and you can check all the parameter values as you are used to debugging other high-level languages.&lt;/p&gt;

&lt;figure&gt;
	&lt;a href=&quot;/images/02/vscode-nodejs-debugging.jpg&quot;&gt;&lt;img src=&quot;/images/02/vscode-nodejs-debugging.jpg&quot; alt=&quot;Visual Studio Code - Node.js debugging&quot; /&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;p&gt;If there are problems, it is mostly because you have forgotten to start the TypeScript compiler once. Therefore, check whether your JavaScript and SourceMap files were generated.&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Visual Studio Code is a great tool for development with Node.js and TypeScript. With just a few lines of code, we have created a web server and a REST Web service. Completely without IIS, Tomcat or Apache HTTP Server.
The example I have deposited here on GitHub:&lt;/p&gt;

&lt;div&gt;&lt;a href=&quot;https://github.com/GregorBiswanger/VSCodeNodejsTypeScriptSample&quot; target=&quot;_blank&quot; class=&quot;btn btn-success&quot;&gt;Code on GitHub&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;Did the article help you? Do you have any questions? Then write me a comment!&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;http://www.cross-platform-blog.com/tools/nodejs/typescript/visual-studio-code-nodejs-with-typescript-and-debugging/&quot;&gt;Visual Studio Code: Node.js with TypeScript and Debugging&lt;/a&gt; was originally published by Gregor Biswanger at &lt;a href=&quot;http://www.cross-platform-blog.com&quot;&gt;Cross-Platform-Blog.com&lt;/a&gt; on January 27, 2017.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Welcome, beautiful new world…]]></title>
 <link rel="alternate" type="text/html" href="http://www.cross-platform-blog.com/general/welcome-javascript/" />
  <id>http://www.cross-platform-blog.com/general/welcome-javascript</id>
  <updated>2017-22-01T00:00:00-00:00</updated>
  <published>2017-01-22T00:00:00+01:00</published>
  
  <author>
    <name>Gregor Biswanger</name>
    <uri>http://www.cross-platform-blog.com</uri>
    <email>gregor.biswanger@web-enliven.de</email>
  </author>
  <content type="html">
    &lt;p&gt;…which I get to know for more than 3 years with JavaScript. After more than 10 years as a .NET expert, it was definitely not an easy step to change my focus. I started as a developer in the business by using PHP. Back then, JavaScript was just a means to an end. I was glad, the lesser I had to use it.&lt;br /&gt;
&lt;!-- more --&gt;&lt;/p&gt;

&lt;p&gt;As excited and ideal platform I got attracted to .NET and C#. I have to admit, in between I gave Visual Basic a try, but it didn’t really made me happy.
I was thrilled by Microsoft and .NET, so I organized a great community in my hometown &lt;a href=&quot;http://www.indot.net&quot; title=&quot;INdotNET&quot; target=&quot;_blank&quot;&gt;Ingolstadt&lt;/a&gt;. I visited communities and conferences around the world and talked about my experiences. I initiated the biggest community roadshows with thousands of attendees. I also wrote books and articles for technical magazines. To make a long story short: I worked hard on my carrier and to be known in the Microsoft developer world.&lt;/p&gt;

&lt;h2 id=&quot;moving-in-a-new-direction&quot;&gt;Moving in a new direction&lt;/h2&gt;
&lt;p&gt;Time changes everything, also the customer requirements. At numerous meetings with customers the most recent topic was „bring your own device“. There were Managers in front of me using their Windows, Mac or Linux computers. Everyone wants to know the true promise of the new software and at the end, the final winner always was the browser. A .NET solution couldn’t pay that much attention anymore. I realized, the focus of .NET changed to the back-end and cloud development. Of course there still is Xamarin, which brings .NET to mobile devices. But it had a lot of disadvantages compared to Apache Cordova while we worked out our proof of concepts.&lt;/p&gt;

&lt;p&gt;When I concentrated on JavaScript and LISP, I could understand Douglas Crockfords statement: &lt;a href=&quot;http://www.crockford.com/javascript/javascript.html&quot; title=&quot;The World's Most Misunderstood Programming Language.&quot; target=&quot;_blank&quot;&gt;„The World’s Most Misunderstood Programming Language“&lt;/a&gt;.
Because of our customer Intel, we approached to Node.js more and more. Projects like Adobe Brackets (where I took part of) are completely developed in Node.js and JavaScript. We completely rewrote our software of CleverSocial from ASP.NET MVC4/Entity Framework/SQL Server to Node.js, Angular 2 and MongoDB. We learned and felt the power of the new JavaScript World. My conclusion has been, that the JavaScript development is way more efficient and faster. At the end you will have a high-speed Cross Platform solution. In this interview of Entwickler.de, I explained in details why I changed my technical focus. I’m afraid, the interview is in German. It’s called “Was .NET-Entwickler über Node.js wissen sollten” which means: &lt;a href=&quot;https://translate.google.de/translate?sl=de&amp;amp;tl=en&amp;amp;js=y&amp;amp;prev=_t&amp;amp;hl=de&amp;amp;ie=UTF-8&amp;amp;u=https%3A%2F%2Fentwickler.de%2Fonline%2Fwindowsdeveloper%2Fdotnet-entwickler-nodejs-wissen-250747.html&amp;amp;edit-text=&quot; title=&quot;What .NET developers should know about Node.js.&quot; target=&quot;_blank&quot;&gt;„What .NET developers should know about Node.js“&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;give-up-everything&quot;&gt;Give up everything?&lt;/h2&gt;
&lt;p&gt;Not at all! Just a week ago, I had a workshop about the .NET development with Microsoft Azure. At the same night I had a speech at my home community, called INdotNET, about XAML. We’re working intensive with a Microservices architecture. If we need a specific strength of .NET, the solution will be exhausted. The data communication of the Entity Framework to the SQL server for example. Then we are using an ASP.NET Core Web-API with Entity Framework Core or even an elderly fully developed Entity Framework 6. Also I will continue on writing my XAML Expertise column for the Windows.Developer-Magazine. Finally I still have a lot of customers who are using WPF.&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;I worked with JavaScript for about 70% of my time and just 30% with .NET in the past 3 years. I got to know all the benefits of JavaScript and I would love to share them with you here on my new blog. You will see how simple the JavaScript development is, to this I will write generally about JavaScript/TypeScript, Tooling, Angular, Node.js, Electron, Cordova, MongoDB and many more.&lt;/p&gt;

&lt;p&gt;Have you changed your focus to JavaScript as well? If so, I would love to hear about your story in the comments below. 
Apart from that, I’m looking forward to share my new knowledge with you. I’m also available for workshops, trainings or consulting. Just send me an E-Mail.&lt;/p&gt;

&lt;p&gt;And now, have a lot of fun on my new blog.&lt;br /&gt;
Gregor&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;http://www.cross-platform-blog.com/general/welcome-javascript/&quot;&gt;Welcome, beautiful new world…&lt;/a&gt; was originally published by Gregor Biswanger at &lt;a href=&quot;http://www.cross-platform-blog.com&quot;&gt;Cross-Platform-Blog.com&lt;/a&gt; on January 22, 2017.&lt;/p&gt;
  </content>
</entry>

</feed>
