Deep Dive into Node.js - Day 1

Over the weekend I decided to finally start a deep dive into Node.js, specificially for a REST API. Coming from a background in C# based SOAP and REST Web Services using ASP.NET I figured this would be the target of my deep dive into node.js.


To get started I downloaded node.js v6.5 Current for Windows (x64). In addition I installed the Node.js Tools 1.2 for Visual Studio 2015, available here. You will also as indicated on the download link need Visual Studio 2015 with Update 3 RTM or higher (I used Update 3 for those curious).

Node.js Deep-Dive

In watching the MVA on Jump Starting Node.js, I started investigating the Express framework for Node.js seeing this as something similar to how WebAPI was to MVC (before the unification recently).

Code wise for this first deep dive I wanted to keep it simple with a GET request that returns the current date time:

var express = require('express');

var app = express();

    function(req, res) {
        res.json({ message: new Date().toLocaleString() });

Pretty simple, include the express module and then define the route to listen in on like you would with AttributeRouting in WebAPI.

Benchmark Setup

To start off, all of the code is in a new github repo DaysInNode. Each day I will make a new folder to keep the tests separate for historical purposes.

Benchmarking wise I wrote a little WPF app utilizing HttpClient to create several GET requests from 10 to 5260 - knowing this is not a 100% true test, again wanted to keep it simple for Day 1.

All benchmarks were run on my i7-6700k (8x4ghz) and 16gb of DDR4 running @ 3200mhz all on Windows 10 Anniversary Edition.

Benchmark Results

To my surprise Node.js was 3X faster than WebAPI (.NET Core) and in some cases even more so as shown in the graph below. In addition memory usage never exceeded 24.8mb while using IIS Express/WebAPI utilized 3.4mb and Kestrel/WebAPI utilized 135mb.

Next up...

Next up in testing is using a NoSQL database on both ends to test a more realistic scenario such as recording a "Like" or "Dislike".
none on this post