Node.js learning progress 2 - Express

Here comes the polar express

As I mentioned in my previous post, I’m learning to write a Node.js web application using MEAN stack now.

Whereas it seems like MEAN.js provides all we want in single package, I prefer to learn a framework one by one. Also, from GitHub repository, if I want to use MEAN I’ll need to use bower and grunt which I’m not familiar with. So, I’ll just start with a simple Express.

Express can be installed using

$ npm install express --save

the –save command means that we want to add express to dependency list in package.json. There also is a express-generator which act like a scaffolding/skeleton helper to make it easier to create an app structure. You can follow the guide here.

From what I see, express is pretty simple and minimal, the only thing that I feel like I need to think is how should we route incoming requests. The site provide us several ways of doing that. Though, sometimes it means more problems to have many options. However, since my app is pretty simple (about 5 pages), I’ll go with the simplest one. In the future, I might try the Namespace routing

Here’s how my directories looks like now.

Structure

Admittedly, this is not the best structure. Later I might consider creating a new directory and put views, model, service directories there but I’ll just leave them like this for now.

You can see the demo here. It’s not working yet, still need to implement Angular.js. and since Angular is on the edge of change, I’m considering waiting for Angular 2.0.

Next thing I want to have a look is Mongoose. Perhaps I’ll use it to store chord progressions for dictionary page.

Node.js pitfall #1

  1. For loop does not work the way you expect.