How I Found A Job With Node + Angular, Part 1: Let’s Do Some Node

After 4 years in AT&T as mobile R&D group manager and system architect (working on AT&T Connect and Unified Communications products) I was leaving and looking for a new position. If you ever looked for an appealing position in the past, you must have connectnoticed a disturbing fact: some of the more attractive positions are offered far far away (geographically speaking) from where you live. At this time in my life I was not willing to move out for a new job (the family really likes our humble neighborhood and community) nor commute to death (in here that meant no more than 1 hour travel for each direction). So my career council shared with me a web site that offered all the relevant companies in my field, with a geographical distribution information, to help me choose the “right” company for me. While this web site was a helping factor in my job search, it was annoying me for its old user interface design, and poor usability. And since I had some free time now, I decided (you know me – if there is something I love it is to learn some new stuff, and fix some broken things) to try to make a better tool for my fellow job seekers.

I was playing with some node.js and angular.js tutorials to get the hang of it for a new application I was designing, so I decided this could be a good learning experieAngularJS-largence for me – to try and build a geographically oriented job seeking utility. As I progressed with it, I captured my findings in this post, so I could share it with you. It is mainly meant for people with some programming background, wnodeho want to experience these new JavaScript technologies. Others could just stick on for the final conclusions towards the end.

I started by following some tutorials and examples I found in node.js site and in angular.js site. I decided to develop on my Windows machine so I installed node.js for Windows. It will also install npm (node packaged modules) for you.

To test that node is working on your machine, try the inevitable “Hello World” test. Open node console in your sources directory and run node (simply type “node“). you should see node prompt, then type:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

You can type it line by line at the console or paste all of it to the console. Once you entered all the lines, open your browser to http://localhost:1337 and you will see “Hello World” staring at you from the page. Your Windows firewall may require you to approve node, and if it does – please approve it so it will not block your application.

Now that you’ve got node running. Let’s install some modules to help us in the making of our application. One very convenient module is express. It will help us rapidly create the web server code, taking most of the boiler plate off our hands.

follow the installation instructions here – in your sources directory create the file :

{
  "name": "hello-world",
  "description": "hello world test app",
  "version": "0.0.1",
  "private": true,
  "dependencies": {
    "express": "3.x"
  }
}

Now run at the node console:

> npm install

If the installation succeeds, you should see a node_modules folder created in your source code folder, with express folder under it.

Now create a “hello.js” file to run our “Hello World” test with express:

var express = require('express');
var app = express();
app.get('/hello.txt', function(req, res){
  res.send('Hello World');
});
var server = app.listen(3000, function() {
    console.log('Listening on port %d', server.address().port);
});

run this with:

> node hello.js

And point your browser to “http”//localhost:3000”. You should see “Cannot GET / “ on the screen. This is good, because it shows that express is listening on port 3000, but since we didn’t define the route to serve “/” requests, it fails. Now try “http://localhost:3000/hello.txt” and you should see the encouraging “Hello World” response.
In the next post we will add some database functionality to our application.

How I Found A Job With Node + Angular tutorial series:

Part 1: Let’s Do Some Node
Part 2: Let’s Level Some Jobs
Part 3: The Angular Angle
Part 4: Strap The Boot
Part 5: Mind The Map
Part 6: Going Production

Leave a Reply

Your email address will not be published. Required fields are marked *