Setting up ASP.NET Core in Visual Studio 2017 with npm, webpack, and TypeScript: Part I

Example code on Github.

Things have been moving so fast in the last couple of years when it comes to web development.  The days of page refreshes on web sites are long gone.  The youngsters and hipsters want ajax, animations, spinners, and what not.  The JavaScript world has exploded with cool libraries and what is the newest, coolest, hottest library right now changes faster than I change my underwear (or maybe I’m just getting old, or I need to change my underwear more often).

Recently, Microsoft came out with the final release of Visual Studio 2017 (VS), and I figured now would be a good time to get my head around ASP.NET Core and all the cool JavaScript things.

The case in mind is a small intranet website that will allow the users to do some quick actuarial calculations.

Getting started
Let’s start by creating a Visual Studio ASP.NET Core project.  Start Visual Studio 2017 and create a new project from the “ASP.NET Core Web Application (.NET Framework)” template.  We will choose this template to make the code compatible with non-Core assemblies (the actuarial assemblies are compiled for .NET 4.5.2).

At the top of the dialog, choose which .NET framework you wish to be compatible with.

In the next dialog choose “Web Application”, and Visual Studio will set up a basic structure for your project.  Among other things, Visual Studio creates a folder named “wwwroot”.  This is where the files that will be published to the actual web server should be placed.  Don’t put anything else such as your code in that folder.

Setting up npm
To get all the JavaScript goodness into our project, we need to install the Node Package Manager (npm). As the name implies, npm is a package manager for JavaScript. Think Nuget for Javascript kind of thing. But npm can do more than that. It can also build TypeScript with the help of webpack which is what we will do later on.

You can install npm (Node.js) through the Visual Studio installer but you should always make sure that you are running the latest version. You can also download and install from the node.js web site.

Now we need to initialize node for our VS project directory. Open a command prompt and cd to the VS project folder (the folder where the .csproj file is located).

Run the command:

npm init -y

This will initialize npm for your project with default settings. The initialization creates a file named package.json. Notice how VS automatically recognizes the file and adds it to the web project.

You might want to open the package.json file and change the name attribute to all lower case since upper case letters are not supported (I have no idea why npm init does not change it to lower case while it is at it).

Run the following command to update npm at a later time.

npm install npm@latest

Installing webpack
Next up is webpack. Webpack seems to be the Swiss Army knife of JavaScript and it looks like people are moving from things like Grunt and Gulp to webpack. Also, in my humble opinion, the webpack documentation is far better than what you will se for a lot of the other “hot and cool” open source JavaScript libraries.

We will be using webpack for compiling TypeScript and for bundling script files.

Install webpack with npm by running the command

npm install webpack --save-dev

This will save webpack as a development (not production) dependency in package.json. We will be using webpack as part of the build process, hence the development dependency. The npm install command also creates a folder named “node_modules” in your project folder with dependencies. Do not include this folder in your project.

In the next part of this series we will get up and running with TypeScript.


Autonomous F16 Wingman

The USAF is testing autonomous wingmen fighter jets.  While I am a sucker for all things fighter jet, especially the F16 Falcon, this is both very fascinating and very unsettling.

Photo via Lockheed Martin.



Top 5 Things, You Shouldn’t Say to a Diabetic

When you are a type 1 diabetic you have to put with a lot of “expert” advice.  Everybody seems to have an opinion on why you have diabetes and how you should treat it.  I put together a list of the top 5 annoying comments (the actual list seems endless):

Number 5:
“Diabetics can eat anything”

This is not entirely wrong. Theoretically I just have to take my insulin. But the amount of insulin is dependent on the amount of carbohydrates I eat. Everytime I eat I need to estimate the number of carbohydrates in my meal and calculate the amount of insulin I should take. This calculation depends on a lot of things like exercise, stress, inflammation, headache – you name it. If the carbohydrates reach my blood faster or slower than the insulin kicks in, or I miscalculate the amount of necessary insulin, my blood sugar can go too low (hypoglycemia – which can kill me now) or too high (hyperglycemia – which can kill me in the long run).  All in all, this is an extremely difficult task and the best advice is to eat slow carbohydrates and not too many.

Number 4:
“Have some cake. It won’t hurt you just this once.”

Maybe not, but if I eat a piece of cake every time someone says that to me, it will definitely hurt me (see number 5).

Number 3:
“This fruit/jam/candy/lemon/cola is organic, so you can eat/drink it. It’s good for you.”

While organic food may be good for you, it still contains lots of fast carbohydrates (see number 5).

Number 2:
“As long as you take your insulin, everything is fine.”

Nope, that’s not how it works. See number 5.

Number 1:
“I guess you should not have been drinking all that coke!”

It is true that I was addicted to Coke (the drink that is) for several years before I was diagnosed with diabetes but type 1 diabetes is an auto-immune disease where the immune system for some reason decides to attack and destroy the insulin-producing cells in the pancreas. This has nothing to do with how much sugar you intake. It is still unclear what causes the immune system to act this way but things such as vira, intestinal diseases, and stress are being investigated – anything that weakens your immune system. Some types of diabetes are even in your genes!.

Type 2 diabetes is a bit of different story. Research shows there is a correlation between type 2 diabetes and an unhealthy way of life.


Welcome – the first blog entry

Welcome to my new blog!

This is where I’ll be posting my ramblings on all things that interest med.  I hope some of it will be of use to you.

Also, check out the about page.