# Saturday, May 7, 2016

Often I want to set up a simple web server to render pages that consist only of client-side code, such as HTML, CSS, and JavaScript. In the past, I've created such pages using Visual Studio, but VS contains more functionality than I need in this case and that functionality can slow me down.

I found a lightweight web server solution in node.js, which is quick to install, quick to start up, and (relatively) simple to use. As a bonus, it will run on multiple operating systems.

Here are the steps I use to create a web server.

  1. Install node
  2. Create and open a folder for your pages
  3. npm Init to create the package.json file that node requires
  4. Create a "views" folder for your pages and add any pages to it
  5. Install express and ejs
  6. Create a main script
  7. Create HTML pages
  8. Start the web server
  9. Try it out

1. Install node

You can download node from https://nodejs.org/en/download/. Select your operating system and run the installer. It is a small download and a quick install.

2. Create and open a folder for your pages.

In Windows, I use the command prompt for this. I create my projects in either the c:\development folder (if I plan to keep them) or the c:\test folder (if they are scratch projects for learning)

So, for a scratch project, I would use the following commands to create a folder named "nodetest1":
cd c:\test

md nodetest1
cd nodetest1 

3. npm Init to create the package.json file that node requires

Node requires a file named package.json with important information about the project. A quick way to create this is with the command "npm Init". It will prompt you for information required by package.json, even providing default values for some of these settings. Press ENTER at a prompt to accept the default in parentheses or override the default by typing in a new setting. Below is an example of me walking through this command, accepting mostly defaults

npm init

This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.  See the session below for reference.

Press ^C at any time to quit.
name: (nodetest1)
version: (1.0.0)
description: best app evar
entry point: (index.js)
test command:
git repository:
keywords:
author: David
license: (ISC)
About to write to C:\test\nodetesting\nodetest1\package.json:
{
  "name": "nodetest1",
  "version": "1.0.0",
  "description": "best app evar",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "David",
  "license": "ISC"
}
Is this ok? (yes) 

As you can see the file you create is echoed to the screen before you confirm its creation.

4. Create a "views" folder for your pages and add any pages to it

The "md" command works for this in the command prompt

md views 

5. Install express and ejs

Express and ejs are packages required for a simple web server. You can use the npm install command to install them. Add the "--save" switch to this command to update the dependencies in your package.json file. The following 2 commands install express and ejs packages, respectively.

npm install --save express
npm install --save ejs 

Check out the package.json and verify that these packages now appear in the dependencies section, as shown in the example below:

"dependencies": {
  "ejs": "^2.4.1",
  "express": "^4.13.4"
} 

6. Create a main script.

Below is the simplest script I could create that serves up any page in the "views" folder and sets a default page. In the example above, I named it "index.js". You can name it whatever you want, but you should set the "main" attribute in package.json to the name of your file. I have commented each line to explain what it does.

// This script uses the express library
var express = require('express');
var app = express(); 
 
// Tell node where to find the view pages
app.set('views', __dirname + '/views'); 
 
// Tell node to use the ejs library to handle the view
app.set('view engine', 'ejs');
app.use(express.static('views'));
app.engine('html', require('ejs').renderFile); 
 
// Set a default page (Optional, but goood to have)
app.get('/', function (req, res) {
    res.render('index.html')
}); 
 
// Start the web server
var server = app.listen(3000, function () {
    console.log("Express is running on port 3000");
}); 

In package.json, you specified a main JavaScript file. (In the example above, I used the default "index.js". Open package.json to see what you set.) This is the script that will run when you run node.

7. Create HTML pages

In the view folder, create some HTML pages. The script above specified "index.html", so we will need to create this one. Create any other page you like and name them with the ".htm" or ".html" extension. Here are 2 simple examples:

Index.html

<html>
    <body>
        <h1>Welcome!</h1>
        <div>
            This is the INDEX page
        </div>
    </body>
</html> 

about.html

<html>
    <body>
        <h1>About Us</h1>
        <div>
            We think therefore we are!
        </div>
    </body>
</html> 

 

8. Start the web server

To start your web server, simply type "node" followed by the name of your main script.  This will launch node and tell you the server is running on port 3000.

9. Try it out

Open a browser and type "http://localhost:3000/" in the address bar. You should see the default page (index.html) displayed. Here is the sample page rendered:

SimpleNodeWebServer1

Type "http://localhost:3000/about.html" to see the "about" sample page described above. If you used my example, you will see the following:
SimpleNodeWebServer2

At the command prompt, press CTRL+C at any time to stop the server, making these pages unavailable.

You can view this sample code at https://github.com/DavidGiard/simplenodewebserver.

Saturday, May 7, 2016 6:55:29 PM (GMT Daylight Time, UTC+01:00)
# Thursday, May 5, 2016

Microsoft Cognitive Services is a set of APIs based on Machine Learning and exposed as REST web services. The Emotion API analyzes pictures of faces and determines the emotion shown in each face.

GCast 15: Cognitive Services - Emotion API

Thursday, May 5, 2016 3:35:00 PM (GMT Daylight Time, UTC+01:00)
# Monday, May 2, 2016
Monday, May 2, 2016 4:21:00 PM (GMT Daylight Time, UTC+01:00)
# Sunday, May 1, 2016

5/1
Today I am grateful for a chance to be part of the Chicago Code Camp keynote yesterday.

4/30
Today I am grateful for:
-My first experience at a FIRST Robotics competition.
-An upgraded flight home last night.

4/29
Today I am grateful for an upgraded hotel room and my first taste of Peruvian food.

4/28
Today I am grateful:
-for dinner last night with Nick, Kathy, and Rick.
-that I arrived safely in St. Louis, despite a rocky start to my trip.
-to Nick for driving me to and from the airport last night.

4/27
Today I am grateful for a hot sauna at the end of a long day.

4/26
Today I am grateful for post-meetup drinks last night with a bunch of JavaScript developers I just met.

4/25
Today I am grateful for breakfast on my balcony in my pajamas.

4/24
Today I am grateful to spend time with Nick and Adriana in Chicago this weekend.

4/23
Today I am grateful for:
-Lunch in the South Loop with Scott yesterday
-Dinner in ChinaTown with Nick and Adriana last night

4/22
Today I am grateful for the variety of people I meet every day.

4/21
Today I am grateful for this view.
ChicagoSkyline (1)
ChicagoSkyline (2)
ChicagoSkyline (3)
ChicagoSkyline (4)

4/20
Today I am grateful to attend the AWS Summit yesterday with Brian and Kevin.

4/19
Today I am grateful that I got my car back with a repaired fender.

4/18
Today I am grateful to sit out on my balcony last night sipping a cocktail and enjoying a warm breeze.

4/17
Today I am grateful for a drink and some beer cheese soup last night with Katie, Justin, and Shira.

4/16
Today I am grateful for:
-Lunch at Wildberry with a bunch of folks from the dev community
-Dinner at a Columbian steakhouse in Lakeview.

4/15
Today I am grateful to see Johnny Clegg in concert last night, after 30+ years as a fan.

4/14
Today I am grateful for lunch with Nonnie yesterday.

4/13
Today I am grateful to get together with my team yesterday, which doesn't happen often enough.

4/12
Today I am grateful that all these family photos are now hanging on the walls of my new apartment.

4/11
Today I am grateful that my taxes are filed.

4/10
Today I am grateful for:
-The opportunity to deliver the keynote presentation at the Tech In 2016 conference yesterday.
-A front-row ticket to see Marshall Crenshaw last night.

4/9
Today I am grateful I was able to track down all my missing tax forms yesterday.

4/8
Today I am grateful for my new cuff links - the first I've received in years!

4/7
Today I am grateful for the power of ibuprofen.

4/6
Today I am grateful for dinner last night with Shelly and her family.

4/5
Today I am grateful to Brian for helping me prepare my upcoming presentation on Virtualization Containers.

4/4
Today I am grateful that I've been able to make it to the gym almost every day for the past 3 months.

Sunday, May 1, 2016 5:14:12 PM (GMT Daylight Time, UTC+01:00)
# Thursday, April 28, 2016

Microsoft Cognitive Services uses Machine Learning to recognize text within pictures and exposes this functionality via a RESTful Web Service.

GCast 14: Cognitive Services - Thumbnail Generation

Thursday, April 28, 2016 12:12:00 PM (GMT Daylight Time, UTC+01:00)
# Monday, April 25, 2016
Monday, April 25, 2016 11:51:00 AM (GMT Daylight Time, UTC+01:00)
# Saturday, April 23, 2016

The Bloody Crown of Conan is the second volume in Del Rey's 3-volume set of the complete Conan stories by Robert Howard. While volume 1: The Coming of Conan the Cimmerian included mostly short stories, this book contains 3 longer works: The People of the Black Circle; The Hour of the Dragon; A Witch Shall Be Born.

BloodyCrownOfConan The Hour of the Dragon is a full novel that takes Conan across many countries of the Hyborian world. It is set in a time when Conan has risen to be king of Aquilonia. Conan's enemies resurrect a dead spirit to enchant the king and steal his throne. Conan's quest to regain the crown leads him across much of the known world, where he fights numerous bottles and raises an army to retake Aquilonia. The action and the epic sweep of this story make it one of Howard's best and enhances this collection.

The other 2 novellas, while not as long or involved as The Hour of the Dragon are more complex than most of Howard's short stories.  By this point in his career, Howard seems to have hit his stride. The action flows freely, if violently, and we can enjoy the adventures of Conan who uses his nearly superhuman strength and skills to overcome nearly impossible odds.

The collection ends with a few uninteresting first drafts of Howard's unpublished Conan stories, followed by a fascinating essay analyzing the themes of the Conan series and the evolution of the character.

For escapism and adventure, it is difficult to beat these stories.

Saturday, April 23, 2016 4:28:00 PM (GMT Daylight Time, UTC+01:00)
# Friday, April 22, 2016
clip_image001

MadHacks is an annual weekend hackathon hosted at the University of Wisconsin in Madison, WI. The organizers decided to move the hackathon from the spring to the fall, which left a gap of nearly 18 months between events. To maintain interest, they decided to host a smaller, 1-day hackathon on April 16. The event was billed as MadHacks Spring Fever.

85 students formed teams and submitted 18 projects.

clip_image003
MadHacks organizers

I served as a mentor and a judge at this hackathon.

I also delivered a 1-hour presentation on Microsoft Cognitive Services.

clip_image005
Presentation on Microsoft Cognitive Services

4 judges evaluated all the submitted projects and chose the top 3. The quality of the projects made this difficult and we had to ask several of the teams to show their project again in order to make a selection.

clip_image007
The judges

Many of the projects were Microsoft branded, such as Xbox games, Azure books, and Microsoft sleeping bags.

The winning projects were:

  1. UniTravel: A mobile application that mapped a route to a destination and calculated not only the time and distance, but also the estimated cost using various transportation options.
  2. Chemical Reactor: A web app that visualized atomic motion and formed new molecules if atoms collided with a force that exceeded the enthalpy required to bond.
  3. Cellular Automata Plant: A web app that visualizes the growth of plant cells over time in a given environment.

 

clip_image009
The UniTravel team
clip_image011
The Chemical Reactor team

The event was organized by University of Wisconsin Microsoft Student Partner Katie Anderson.

The projects created were particularly impressive, given that they were all created in 12 hours or less.

A much larger hackathon is planned at UW-Madison in the fall semester.

Friday, April 22, 2016 1:46:00 PM (GMT Daylight Time, UTC+01:00)
# Thursday, April 21, 2016

Microsoft Cognitive Services uses Machine Learning to recognize text within pictures and exposes this functionality via a RESTful Web Service.

Cognitive Services - Optical Character Recognition

Thursday, April 21, 2016 11:52:00 AM (GMT Daylight Time, UTC+01:00)
# Wednesday, April 20, 2016

clip_image001

The idea for the Global Azure Boot Camp began in 2013. Community developers from all over the world would hold a workshop in different cities on the same day. In fact, I organized and delivered a Boot Camp in the Detroit area that year, before I joined Microsoft.

On Saturday April 18, the 4th annual Global Azure Boot Camp took place in 161 cities around the world. While some cities focused on presentations and others on hands-on labs, all events provided education on Microsoft’s cloud computing platform.

Microsoft Regional Director Eric Boyd and Responsive X organized an event in Addison, IL – just outside of Chicago. Based on feedback, he received from attendees last year, Eric decided to reduce the length of the event to a half day, instead of a full day. The event was free to the public.

Eric kicked off the morning with an overview of Azure.

clip_image002

Next, a representative from Baracuda Networks gave a presentation on Azure security.

I delivered a session on App Services, covering Web Apps, Mobile Apps, Logic Apps, and API Apps.

clip_image004

The only downside to the Saturday event was the number of people who registered and did not attend – over 50%. This was almost certainly due to the fact that the Chicago weather that morning was the nicest it had been in a long time. Still, over 60 people showed up to learn about Azure and cloud computing.

Response from the audience was overwhelmingly positive. Many people stayed after to ask questions about Azure and about BizSpark.

Wednesday, April 20, 2016 2:37:01 PM (GMT Daylight Time, UTC+01:00)