Welcome to Node.js: Part 3 – Express and AngularJS
July 1, 2014
As I’ve said before, I’m still a novice in the programming arena. In our quest to understand Node.js and the tools surrounding it, we’ve come to the “EA” in the MEAN stack. Express and AngularJS seemed, insofar as I could tell from a mere surface-level investigation, really simple to use and impossible to explain.
Everywhere I looked, tutorials told me how to install Express and use it to set up simple static servers, but there was little if any explanation of what it actually is. Much of my confusion came down to the difference between libraries and frameworks. I understand libraries well enough—they’re a relatively low-level concept in programming, and pretty much every useful program ever written depends on them to some extent. If you happen to be coming at this without knowing about libraries, you can check out the Wikipedia page on them, but they’re really just a collection of methods you can include in your code: name the collection in the relevant location in the program, and then use the methods as though you’d declared them yourself.
Imagine writing instructions to someone for doing a given task. They’ll follow those instructions word for word, but when they get to a task that they don’t know, you need to provide the name of a book with the explanation in it, or a library that has that book in it. Then your buddy can look it up for himself and continue on with the overall activity. Other people have already written instructions for those special tasks, so you point him in the right direction instead of writing it all out again. That’s pretty much how a programming library works.
a framework is a frame of patterns and functions that make sure your project can behave in certain ways.
I’m less familiar with frameworks. Most of the instructions I read for Express seemed to speak of frameworks in a similar way to libraries. “So why,” I asked myself, “do they insist on using different terms?” When I finally stopped looking for an explicit anatomy of Express and searched for a general explanation of frameworks, I finally made some headway. As far as I can tell, frameworks are kind of like a structure or blueprint—a pattern that ensures your program is informed about what is expected and conforms to that expectation.
A framework can (and usually does) include a great number of internal libraries of its own. So, a library is a bit of specific functionality you can inject into a project, and a framework is (cough) a frame of patterns and functions that make sure your project can behave in certain ways.
So now we can approach Express and AngularJS. After finally understanding a little more of frameworks, I can accept that Express is just the most popular framework for Node.js projects. As for AngularJS, most sources seem to assume it is a framework, too, even though (somehow) it technically is somewhere between a library and a framework. However, it also seems to occupy the most tenuous position in the MEAN stack. There are several other tools that can be used in place of AngularJS (Backbone.js, Ember.js, Jade, etc.). I really don’t know enough to know (yet) what sets one apart from the other, but Angular does have the added benefit of being developed and maintained by Google, so continued support for it is all but guaranteed. Here’s a generous introduction to some of Angular’s capabilities.
Part of learning is learning how much I don’t know. That seems doubly true on the tech front, and Node.js is no exception. However, I can certainly say I know more now than I did before, and I hope you can say the same. Now that we’ve downloaded and installed Node.js (in Part 1), and figured out a little more about the necessary components around it, we can move on to acquiring these components in the next post.