Thursday, September 24, 2015

Understanding DNX

Getting a handle on the new .NET Execution Environment (DNX) is difficult. I've been following the project for a while, and still get twisted around trying to explain it to people. I believe the following analogy and diagram help to understand the environment.

Keep in mind, this is a tenuous comparison meant to help people understand the environment. It is not a comparison of the technologies in question.

I often compare DNX and its ecosystem to the MEAN development stack (MongoDB, ExpressJS, AngularJS, and NodeJS). This development stack consists of a runtime environment (NodeJS) that hosts a framework for creating server-side applications (ExpressJS). These server-side applications can be accessed using client-side frameworks such as AngularJS. The entire stack can be backed with MongoDB for permanent storage.

The DNX environment is similar, but much richer. DNX is the runtime environment, much like NodeJS is for the MEAN stack. MVC can be used to create an API (formerly WebAPI*) that runs on the server in DNX, much like ExpressJS is used in the MEAN stack. The client-side component can still be AngularJS that calls the API. This is where the comparison ends.

DNX is unique in that it requires an implementation of .NET to be available in order for it to serve up applications. As of the Beta7 release, it can use either Mono or CoreCLR. This requirement allows software developers to completely control the environment in which their application lives, by choosing either Mono or CoreCLR as the backing .NET implementation.

The best part is that all of this can be run on Windows, Mac, and Linux! DNX enables developers to completely control their application's environment and runtime.

In my analogy, I left out the backing database technology in the DNX ecosystem. As the CoreCLR advances, it will enable applications to access SQL Server natively. This capability means that an app running on a non-Windows operating system will have "native" access to SQL Server.

Below is a basic diagram showing how the DNX landscape looks. Not all of the functionality depicted is currently available, but an awful lot of it is.

Since the DNX environment is changing rapidly, I would appreciate any feedback as to anything I have stated that is incorrect.

Tuesday, September 15, 2015

First Node.js App in Azure

I read Ted Neward's article about deploying a simple Node.js app to Microsoft Azure and wanted to give it a try.

The steps mostly worked, except for a few issues. Below are the steps that he lays out. I am assuming that you have clicked the link and read the article. He does a much better job explaining everything. In this post, I wanted to note the changes necessary with the steps.

  1. In a local directory, create the following Javascript file. This file creates a basic web server using Node.js.
           var http = require('http');
           var port = process.env.PORT || 3000;
           http.createServer(function(req, res) {
             res.writeHead(200, { 'Content-Type': 'text/plain' });
             res.end('Hello World');
           }).listen(port);
         
    In the article, this script is named "helloHTTP.js." For the file to work in Azure, it needs to be named "server.js".
  2. Test the script using Node.js
    1. Run the script using Node.js:
      node server.js
    2. Open the URL http://localhost:3000 in your browser.
    3. You should see the string "Hello World".
  3. Install the azure-cli tools:
    npm install -g azure-cli
  4. Access your Azure account:
    azure account download
  5. Import the file that was just downloaded:
    azure account import 
  6. Create the site with git:
    azure site create --git
    In the article, the argument for the git option only showed a single dash. Also, this step will prompt you for a site user name and region. The name you choose must be unique across Azure. Pay attention to the messages too. It will give you the full URL necessary for accessing the site once it is created.
  7. Add the script file:
    git add server.js
  8. Commit the file:
    git commit -m "Initial site creation."
  9. Push the site to Azure:
    git push azure master
At this point, you should be able to navigate to the site name created above, and see "Hello World" generated by a Node.js script in Azure.