LAMP diehards take note: The flexible simplicity of MongoDB, ExpressJS, AngularJS, and Node.js is no joke
The transition from cutting-edge curiosity to practical workhorse is
not one that many technologies make. Yesterday’s precocious upstarts
often fail to live up to their Version 0.1 promise -- not so for the
technologies that make up the fiercely acronymized MEAN stack.
It
was only a few years ago that MongoDB, Express.js, AngularJS, and
Node.js were raising eyebrows on their own. Now they’ve grown up and
ganged up, and together they’re doing serious work, poaching no small
number of developers from the vast LAMP camp. But how exactly does this
newfangled MEAN thing stack up against LAMP? When is it better to choose
the well-tested, mature LAMP over this upstart collection of
JavaScript-centric technologies?
The answer is when the simplicity and common structure make your life
easier. MongoDB offers a more flexible, accommodating layer for storing
data. Node.js provides a better nexus for running your server, while
Express.js helps standardize how you build your websites. On the client,
AngularJS provides a clean way of adding interactive functions and
AJAX-driven rich components. Put them all together and they make a
clean, coherent mechanism for moving data from user to disk farm and
back again.
The real explanation, however, is deeper. Here we
offer nine reasons to give MEAN a shot with your next project. Not
everyone has the time or budget to toss out and recode the old in the
latest, trendiest framework, nor should you throw away the rock-solid
reliability of battle-tested tools like Apache, MySQL, or PHP. But for
green-field projects that could benefit from flexibility, simplicity,
and performance, going MEAN may make your life better than you think.
MongoDB is built for the cloud
If
your Web app plans include making good on the pennies-per-CPU promise
of the cloud, the MEAN stack offers a compelling database layer in
MongoDB. This modern database comes equipped with automatic sharding and
full cluster support, right out of the box. Plug in MongoDB and it
spreads across your cluster of servers to offer failover support and
automatic replication. Given the ease with which apps can be developed,
tested, and hosted in the cloud, there’s little reason not to consider
MongoDB for your next project.
MySQL's structure is confining (and overrated)
Anyone
who has developed or maintained a LAMP-based app for any amount of time
knows that MySQL’s strength as a relational database can feel a bit
imprisoning at times. Like all relational databases, MySQL forces you to
push your data into tables. This isn't a problem if every single entry
fits into exactly the same format, but how often is the world that
generous? What if two people share the same address but not the same
account? What if you want to have three lines to the address instead of
two? Who hasn’t tried to fix a relational database by shoehorning too
much data into a single column? Or else you end up adding yet another
column, and the table grows unbounded.
MongoDB, on the other hand,
offers a document structure that is far more flexible. Want to add a
new bit of personal information to your user profiles? Simply add the
field to your form, roll it up with the rest of the data in a JSON
document, and shove it into your MongoDB collection. This is great for
projects in flux and for dealing with data that may ultimately prove
tricky to constrain in table form.
Disk space is cheap
Among the great revelations of relational
databases was the JOIN command. With JOIN, we could save disk space by
removing repeated fields like city, state, and ZIP code. By storing this
frequently accessed and repeated data in separate tables that can be
included in future results through a JOIN, we keep our database tidy and
our disks slim.
But JOINs can be tricky for some and hard on RAM,
and though it's still a good idea to isolate and access data in
separate tables through JOINs, there's not as much need to save disk
space now that disk drives are measured in multiple terabytes. The space
is so cheap that some database designers end up denormalizing their
data because the JOINs are too slow. Once you do that, you don't need a
relational database as much. Why not use MongoDB instead?
Node.js simplifies the server layer
Navigating
the various layers of the LAMP stack can be a difficult dance of many
hats, one that has you shuffling through various config files with
differing syntax. MEAN simplifies this through use of Node.js.
Want
to change how your app routes requests? Sprinkle in some JavaScript and
let Node.js do the rest. Want to change the logic used to answer
queries? Use JavaScript there as well. If you want to rewrite URLs or
construct an odd mapping, it's also in JavaScript. The MEAN stack’s
reliance on Node.js put this kind of pipework all in one place, all in
one language, all in one pile of logic. You don't need to reread the man
pages for PHP, Apache, and whatever else you add to the stack. While
the LAMP generation has different config files for everything, Node.js
avoids that issue altogether. Having everything in one layer means less
confusion and less chance of strange bugs created by weird interactions
between multiple layers.
MEAN makes code isomorphic
The simplicity doesn't stop with using JavaScript on the server. By
going MEAN, you can enjoy that same JavaScript on the client, too,
leaving behind the LAMP stack's client/server schizophrenia. If you
write code for Node and decide it’s better placed in AngularJS, you can
move it over with ease, and it's almost certain to run the same way.
This flexibility makes programming MEAN-based apps significantly easier.
Plus, if you're staffing up a project, you don't need to look for a PHP
expert and a JavaScript expert, or a front-end and a back-end
specialist. Instead, it’s all JavaScript across the stack.
JSON everywhere
AngularJS
and MongoDB both speak JSON, as do Node.js and Express.js. The data
flows neatly among all the layers without rewriting or reformatting.
MySQL's native format for answering queries is, well, all its own. Yes,
PHP already has the code to import MySQL data and make it easy to
process in PHP, but that doesn't help the client layer. This may be a
bit minor to seasoned LAMP veterans because there are so many
well-tested libraries that convert the data easily, but it all seems a
bit inefficient and confusing. MEAN uses the same JSON format for data
everywhere, which makes it simpler and saves time reformatting as it
passes through each layer. Plus, JSON’s ubiquity through the MEAN stack
makes working with external APIs that much easier: GET, manipulate,
present, POST, and store all with one format.
Node.js is superfast
Apache was great, but these days, Node.js is often flat-out faster. A number of benchmarks show that Node.js offers better performance,
while doing much more. Perhaps it's the age of the code. Perhaps the
Node.js event-driven architecture is quicker. It doesn't matter. These
days, especially among impatient mobile device users, shaving even
milliseconds off your app’s performance is important and Node.js can do
that, while offering a Turing-complete mechanism for reprogramming it.
Depth matters
PHP
lovers like to cling to the great libraries of code that are built for
dominant platforms like WordPress or Drupal. They have good reasons to
be proud, but their advantages are evaporating as Node.js catches up.
The Node.js package manager, Npm,
makes it even easier to share code, and the public repositories
targeting Node.js are growing quickly. While the PHP crowd may lead at
this moment in time, the future may favor Node.js. Plus, incumbents
often prove to be brittle in the face of shifting trends. Each attempt
to modernize an entrenched platform like Drupal with a new version means
that many more developers may be letting their eyes wander toward the
newer, more nimble platforms built around Node.js.
AngularJS is fresh
It's not exactly fair to compare the "A"
in "MEAN" with anything in the LAMP stack because LAMP doesn't include
an analog. If you want to do anything on the client side, you're on your
own. Sure, there are plenty of good PHP-based frameworks that work with
MySQL, but each is a bit different and moving in its own direction.
WordPress, Joomla, and Drupal, for example, offer differing strategies,
and it's hard to switch between them, let alone port code from one to
the other. Anointing one client framework adds consistency and
stability.
It also helps that AngularJS was built by folks with 20
years of experience building Web apps. They knew well enough to leave
the design work to HTML and CSS. They also figured out how to add a bit
of JavaScript to scan the HTML. The designers of AngularJS looked at
what humans do well, then tailored the JavaScript to support the humans.
The templating system and the logic layers are dramatically cleaner
than what we've seen before, in part because the team figured out
simpler ways to leverage the local power of JavaScript to guess what you
are doing.
Mix and match
Of course, if you're really
picky, there's no reason why you can't mix it up a bit. Plenty of
developers use MongoDB with Apache and PHP, and others prefer to use
MySQL with Node.js. AngularJS works quite well with any server, even one
running PHP to deliver data from MySQL. You don't have to be a slave to
the acronyms.
Source: http://www.infoworld.com
No comments:
Post a Comment