Chapter 1. Introducing Full-Stack Development
Chapter 1. Introducing Full-Stack Development
js 2ED
now
1.3. Introducing Express: The framework
1.3.1. Easing your server setup
1.3.2. Routing URLs to responses This chapter covers
1.3.3. Views: HTML responses Evaluating full-stack development
1.3.4. Remembering visitors with session Getting to know the MEAN stack components
support Examining what makes the MEAN stack so compelling
1.4. Introducing MongoDB: The database Previewing the application you’ll build throughout this
1.4.1. Relational databases vs. document book
stores
1.4.2. MongoDB documents: JavaScript
data store
If you’re like us, you’re probably impatient to dive into some code and get
1.4.3. More than just a document database
on with building something. But let’s take a moment first to clarify what w
1.4.4. What is MongoDB not good for?
1.4.5. Mongoose for data modeling mean
and by full-stack development and look at the component parts of the
more stack to make sure that you understand each one.
1.5. Introducing Angular: The front-end
framework
When we talk about full-stack development, we’re really talking about
1.5.1. jQuery vs. Angular
developing all parts of a website or application. The full stack starts with
1.5.2. Two-way data binding: Working with
the database and web server in the back end, contains application logic an
data in a page
control in the middle, and goes all the way through to the user interface at
1.5.3. Using Angular to load new pages
the front end.
1.5.4. Are there any downsides?
1.5.5. Developing in TypeScript
The MEAN stack is a pure JavaScript stack comprised of four main
1.6. Supporting cast
technologies, with a cast of supporting technologies:
1.6.1. Twitter Bootstrap for user interface
1.6.2. Git for source control
MongoDB—the database
1.6.3. Hosting with Heroku
Express—the web framework
1.7. Putting it together with a practical
Angular—the front-end framework
example
Node.js—the web server
1.7.1. Introducing the example application
1.7.2. How the MEAN stack components
work together MongoDB has been around since 2007 and is actively main
maintained by
MongoDB, Inc., previously known as 10gen.
Ch 2 Designing a MEAN stack architecture
Angular is open source and backed by Google. The first version of Angular
known as AngularJS or Angular 1, has been around since 2010. Angular 2,
now known simply as Angular, was officially released in 2016 and is
continually being developed and extended. The current version is Angular
7.1; Angular 2+ isn’t backward-compatible with AngularJS. See the sidebar
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 1/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
“Angular versions and release cycles” for a bit more information about th
number and release cycles.
Back in the early days of the web, people didn’t have high expectations of
websites. Not much emphasis was given to presentation; building website
was much more about what was going on behind the scenes. Typically, if
you knew something like Perl and could string together a bit of HTML, you
were a web developer.
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 2/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
increased browser support for Cascading Style Sheets (CSS) and JavaScrip
this interest led to more-complicated front-end implementations. It was
no longer a case of being able to string together HTML; you needed to
table of contents spend
index time on CSS and JavaScript, making sure that it looked right and
1.2.1. JavaScript: The single language
worked as expected. And all this needed to work in different browsers,
through the stack less compliant than they are today.
which were much
1.2.2. Fast, efficient, and scalable
1.2.3. Using prebuilt packages via npm buy
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 3/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
build both the front end and the application logic behind it, as figure 1.2
shows.
now
1.3. Introducing Express: The framework
1.3.1. Easing your server setup
1.3.2. Routing URLs to responses
1.3.3. Views: HTML responses
1.3.4. Remembering visitors with session
support
1.4. Introducing MongoDB: The database
1.4.1. Relational databases vs. document
stores
1.4.2. MongoDB documents: JavaScript
data store
1.4.3. More than just a document database
1.4.4. What is MongoDB not good for?
1.4.5. Mongoose for data modeling and
more
1.5. Introducing Angular: The front-end
framework
1.5.1. jQuery vs. Angular
1.5.2. Two-way data binding: Working with
data in a page
1.5.3. Using Angular to load new pages
1.5.4. Are there any downsides? Figure 1.2 illustrates a trend rather than proclaims a definitive “all web
developers should be full-stack developers” maxim. There have been full-
1.5.5. Developing in TypeScript
stack developers throughout the entire history of the web, and moving
1.6. Supporting cast
forward, it’s most likely that some developers will choose to specialize in
1.6.1. Twitter Bootstrap for user interface
either front-end or back-end development. The intention is to show that
1.6.2. Git for source control
through the use of frameworks and modern tools, you no longer have to
1.6.3. Hosting with Heroku
choose one end or the other to be a good web developer.
1.7. Putting it together with a practical
example
A huge advantage in embracing the framework approach is that you can b
1.7.1. Introducing the example application
incredibly productive, because you’ll have an all-encompassing vision of
1.7.2. How the MEAN stack components
work together the application and how it ties together.
Ch 2 Designing a MEAN stack architecture
Moving the application code forward in the stack
Continuing with the trend toward frameworks, the past few years have
seen an increasing effort to move the application logic away from the
server and into the front end. Think of this as coding the back end in the
front end. Some of the most popular JavaScript frameworks doing this are
Angular, React, and Vue.js.
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 4/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
Tightly coupling the application code to the front end this way tends to blu
the lines between traditional front-end and back-end developers. One of
the reasons why people like to use this approach is that it reduces the load
table of contents onindex
the servers, thus reducing cost. What you’re doing in effect is
1.2.1. JavaScript: The single language
crowdsourcing the computational power required for the application by
through the stack
pushing that load into users’ browsers.
1.2.2. Fast, efficient, and scalable
1.2.3. Using prebuilt packages via npm buy
now
We’ll discuss the pros and cons of this approach in section 1.5 and explain
1.3. Introducing Express: The framework
when it may (or may not) be appropriate to use one of these technologies.
1.3.1. Easing your server setup
1.3.2. Routing URLs to responses
1.1.2. The trend toward full-stack developing
1.3.3. Views: HTML responses
1.3.4. Remembering visitors with session
As discussed, the paths of front-end and back-end developers are mergin
support
it’s entirely possible to be fully proficient in both disciplines. If you’re a
1.4. Introducing MongoDB: The database
freelancer, consultant, or part of a small team, being multiskilled is
1.4.1. Relational databases vs. document
stores extremely useful, increasing the value that you can provide for your client
Being able to develop the full scope of a website or application gives you
1.4.2. MongoDB documents: JavaScript
data store better overall control and can help the parts work seamlessly together,
because they haven’t been built in isolation by separate teams.
1.4.3. More than just a document database
1.4.4. What is MongoDB not good for?
1.4.5. Mongoose for data modeling If
andyou work as part of a large team, chances are that you’ll need to
more specialize in (or at least focus on) one area. But it’s generally advisable to
understand how your component fits with other components, giving you a
1.5. Introducing Angular: The front-end
framework greater appreciation of the requirements and goals of other teams and the
1.5.1. jQuery vs. Angular overall project.
1.5.2. Two-way data binding: Working with
data in a page
In the end, building on the full stack yourself is rewarding. Each part come
1.5.3. Using Angular to load new pages
with its own challenges and problems to solve, keeping things interesting
1.5.4. Are there any downsides?
The technology and tools available today enhance this experience and
1.5.5. Developing in TypeScript
empower you to build great web applications relatively quickly and easily.
1.6. Supporting cast
1.6.1. Twitter Bootstrap for user interface
1.1.3. Benefits of full-stack development
1.6.2. Git for source control
1.6.3. Hosting with Heroku There are many benefits to learning full-stack development. For starters,
1.7. Putting it together with a practicalthere’s the enjoyment of learning new things and playing with new
example
technologies, of course. Then you have the satisfaction of mastering
1.7.1. Introducing the example application
something different and the thrill of being able to build and launch a full
1.7.2. How the MEAN stack components
database-driven application all by yourself.
work together
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 5/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
livebook features:
discuss
Ask a question, share an example, or respond to another reader. Start a thread by selecting any
piece of text and clicking the discussion icon.
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 6/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
In the late 1990s, Microsoft released Active Server Pages (now known
as Classic ASP). ASP could be written in VBScript or JavaScript, but the
JavaScript version didn’t take off, largely because at the time, a lot of
people were familiar with Visual Basic, which VBScript looks like. Many
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 7/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
table of contents indexthe release of Node.js, you can use what you already know and put it
With
1.2.1. JavaScript: The single language
use on the server. One of the hardest parts of learning a new technology lik
through the stack
this is learning the language, but if you already know some JavaScript,
1.2.2. Fast, efficient, and scalable
you’re one step ahead!
1.2.3. Using prebuilt packages via npm buy
now
1.3. Introducing Express: The framework
There’s a learning curve when you’re taking on Node.js, even if you’re an
1.3.1. Easing your server setup
experienced front-end JavaScript developer. The challenges and obstacles
1.3.2. Routing URLs to responses
in server-side programming are different from those on the front end, bu
1.3.3. Views: HTML responses
you’ll face those challenges no matter what technology you use. On the
1.3.4. Remembering visitors with session
front end, you may be concerned about making sure that everything work
support
in a variety of browsers on different devices. On the server, you’re more
1.4. Introducing MongoDB: The database
likely to be aware of the flow of the code to ensure that nothing gets held u
1.4.1. Relational databases vs. document
stores and that you don’t waste system resources.
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 8/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
now
1.3. Introducing Express: The framework
1.3.1. Easing your server setup
1.3.2. Routing URLs to responses
1.3.3. Views: HTML responses
1.3.4. Remembering visitors with session
support
1.4. Introducing MongoDB: The database
1.4.1. Relational databases vs. document
stores
1.4.2. MongoDB documents: JavaScript
data store
1.4.3. More than just a document database
1.4.4. What is MongoDB not good for?
1.4.5. Mongoose for data modeling and
more
1.5. Introducing Angular: The front-end
framework
1.5.1. jQuery vs. Angular
1.5.2. Two-way data binding: Working with
data in a page
1.5.3. Using Angular to load new pages
1.5.4. Are there any downsides?
1.5.5. Developing in TypeScript
You can see in figure 1.4 that Simon goes to bank teller 1, and Sally goes to
1.6. Supporting cast
bank teller 2. Neither side is aware of or affected by the other. Bank teller 1
1.6.1. Twitter Bootstrap for user interface
deals with Simon, and nobody else, throughout the entirety of the
1.6.2. Git for source control
transaction; the same goes for bank teller 2 and Sally.
1.6.3. Hosting with Heroku
1.7. Putting it together with a practical
example This approach works perfectly well as long as you have enough tellers to
service the customers. When the bank gets busy and the customers
1.7.1. Introducing the example application
1.7.2. How the MEAN stack components outnumber the tellers, the service starts to slow and the customers have t
work together wait to be seen. Although banks don’t always worry about this situation to
much and seem happy to make you stand in line, the same isn’t true of
Ch 2 Designing a MEAN stack architecture
websites. If a website is slow to respond, users are likely to leave and neve
come back.
This is one of the reasons why web servers are often overpowered and hav
so much RAM, even though they don’t need it 90% of the time. The
hardware is set up in such a way as to be prepared for a huge spike in traffi
This setup is like the bank hiring an additional 50 full-time tellers and
moving to a bigger building because it gets busy at lunchtime.
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 9/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
Surely there’s a better way—a way that’s a bit more scalable. Here’s wher
the single-threaded approach comes in.
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 10/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
now
1.3. Introducing Express: The framework
1.3.1. Easing your server setup
1.3.2. Routing URLs to responses
1.3.3. Views: HTML responses
1.3.4. Remembering visitors with session
support
1.4. Introducing MongoDB: The database
1.4.1. Relational databases vs. document
stores
1.4.2. MongoDB documents: JavaScript
data store
1.4.3. More than just a document database
1.4.4. What is MongoDB not good for?
1.4.5. Mongoose for data modeling and
more
1.5. Introducing Angular: The front-end
framework
1.5.1. jQuery vs. Angular
1.5.2. Two-way data binding: Working with
data in a page
1.5.3. Using Angular to load new pages
1.5.4. Are there any downsides?
1.5.5. Developing in TypeScript
1.6. Supporting cast
1.6.1. Twitter Bootstrap for user interface
1.6.2. Git for source control In the single-threaded approach shown in figure 1.5, Sally and Simon give
1.6.3. Hosting with Heroku their requests to the same bank teller. But instead of dealing with one of
them exclusively before the next, the teller takes the first request and
1.7. Putting it together with a practical
example passes it to the best person to deal with it before taking the next request
1.7.1. Introducing the example application
and doing the same thing. When the teller is told that a requested task is
complete, the teller passes the result back to the visitor who made the
1.7.2. How the MEAN stack components
work together request.
Ch 2 Designing a MEAN stack architecture
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 11/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
For the single-threaded approach to work, you must make sure thatnow
1.3. Introducing Express: The framework
your code is nonblocking. The way to achieve this is to make any
1.3.1. Easing your server setup
blocking operations run asynchronously, preventing them from
1.3.2. Routing URLs to responses
blocking the flow of your main process.
1.3.3. Views: HTML responses
1.3.4. Remembering visitors with session
support Despite there being a single teller, neither of the visitors is aware of the
1.4. Introducing MongoDB: The databaseother, and neither is affected by the requests of the other. This approach
means that the bank doesn’t need several tellers always on hand. This
1.4.1. Relational databases vs. document
stores model isn’t infinitely scalable, of course, but it’s more efficient. You can d
more with fewer resources. It doesn’t mean, however, that you’ll never
1.4.2. MongoDB documents: JavaScript
data store need to add more resources.
1.4.3. More than just a document database
1.4.4. What is MongoDB not good for?
This particular approach is possible in Node.js due to the asynchronous
1.4.5. Mongoose for data modeling capabilities
and of JavaScript, as you’ll see in action throughout the book. But
more
you’re not sure about the theory, check out appendix D (available online o
1.5. Introducing Angular: The front-end
in the e-book), particularly the section on callbacks.
framework
1.5.1. jQuery vs. Angular
1.5.2. Two-way data binding: Working 1.2.3.
withUsing prebuilt packages via npm
data in a page
A package manager, npm, gets installed when you install Node.js. npm
1.5.3. Using Angular to load new pages
gives you the ability to download Node.js modules or packages to extend th
1.5.4. Are there any downsides?
functionality of your application. Currently, more than 350,000 packages
1.5.5. Developing in TypeScript
are available through npm, an indication of how much depth of knowledge
1.6. Supporting cast
and experience you can bring to an application. This figure is up from
1.6.1. Twitter Bootstrap for user interface
46,000, when the first edition of Getting MEAN was written four years ago
1.6.2. Git for source control
1.6.3. Hosting with Heroku
Packages in npm vary widely in what they give you. You’ll use some npm
1.7. Putting it together with a practical
packages throughout this book to bring in an application framework and a
example
database driver with schema support. Other examples include helper
1.7.1. Introducing the example application
libraries such as Underscore, testing frameworks like Mocha, and utilities
1.7.2. How the MEAN stack components
work together like Colors, which adds color support to Node.js console logs. You’ll look
more closely
at npm and how it works when you start building an
Ch 2 Designing a MEAN stack architecture
application in chapter 3.
livebook features:
settings
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 12/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
Update your profile, view your dashboard, tweak the text size, or turn on dark mode.
view how
now
how it should be set up or used, which is one of its great strengths. But
1.3. Introducing Express: The framework
1.3.1. Easing your server setup every time you create websites and web applications, quite a few common
tasks need doing. Express is a web application framework for Node.js that
1.3.2. Routing URLs to responses
designed to perform these tasks in a well-tested, repeatable way.
1.3.3. Views: HTML responses
1.3.4. Remembering visitors with session
support 1.3.1. Easing your server setup
1.4. Introducing MongoDB: The database
As already noted, Node.js is a platform, not a server, which allows you to
1.4.1. Relational databases vs. document
stores get creative with your server setup and do things that you can’t do with
other web servers. It also makes getting a basic website up and running
1.4.2. MongoDB documents: JavaScript
data store harder.
1.4.3. More than just a document database
1.4.4. What is MongoDB not good for?
Express abstracts away this difficulty by setting up a web server to listen t
1.4.5. Mongoose for data modeling incoming
and requests and return relevant responses. In addition, it defines a
more directory structure. One folder is set up to serve static files in a nonblockin
1.5. Introducing Angular: The front-end
way; the last thing you want is for your application to have to wait when
framework
someone requests a CSS file! You could configure this yourself directly in
1.5.1. jQuery vs. Angular
Node.js, but Express does it for you.
1.5.2. Two-way data binding: Working with
data in a page
1.3.2. Routing URLs to responses
1.5.3. Using Angular to load new pages
1.5.4. Are there any downsides?
One of the great features of Express is that it provides a simple interface fo
1.5.5. Developing in TypeScript
directing an incoming URL to a certain piece of code. Whether this interfac
1.6. Supporting cast will serve a static HTML page, read from a database, or write to a database
1.6.1. Twitter Bootstrap for user interface
doesn’t matter. The interface is simple and consistent.
1.6.2. Git for source control
1.6.3. Hosting with Heroku Express abstracts away some of the complexity of creating a web server in
1.7. Putting it together with a practicalnative Node.js to make code quicker to write and easier to main
maintain.
example
1.7.1. Introducing the example application
1.3.3. Views: HTML responses
1.7.2. How the MEAN stack components
work together
It’s likely that you’ll want to respond to many of the requests to your
Ch 2 Designing a MEAN stack architecture
application by sending some HTML to the browser. By now, it will come as
no surprise to you that Express makes this task easier than it is in native
Node.js.
Express provides support for many templating engines that make it easier
to build HTML pages in an intelligent way, using reusable components as
well as data from your application. Express compiles these together and
serves them to the browser as HTML.
now
1.3. Introducing Express: The framework
You’ll never guess what: Express has an answer to this problem too!
1.3.1. Easing your server setup
Express can use sessions so that you can identify individual visitors throug
1.3.2. Routing URLs to responses
multiple requests and pages. Thank you, Express!
1.3.3. Views: HTML responses
1.3.4. Remembering visitors with session
support Sitting on top of Node.js, Express gives you a great helping hand and a
1.4. Introducing MongoDB: The databasesound starting point for building web applications. It abstracts away many
complexities and repeatable tasks that most of us don’t need—or want—t
1.4.1. Relational databases vs. document
stores worry about. We only want to build web applications.
1.4.2. MongoDB documents: JavaScript
data store
1.4.3. More than just a document database
livebook features:
1.4.4. What is MongoDB not good for?
highlight, annotate, and bookmark
1.4.5. Mongoose for data modeling and
more Select a piece of text and click the appropriate icon to comment, bookmark, or highlight
1.5. Introducing Angular: The front-end
framework view how
1.5.1. jQuery vs. Angular
1.5.2. Two-way data binding: Working with
data in a page
1.4. Introducing MongoDB: The database
1.5.3. Using Angular to load new pages
1.5.4. Are there any downsides? The ability to store and use data is vital for most applications. In the MEAN
1.5.5. Developing in TypeScript stack, the database of choice is MongoDB, the M in MEAN. MongoDB fits
1.6. Supporting cast into the stack incredibly well. Like Node.js, it’s renowned for being fast an
1.6.1. Twitter Bootstrap for user interface
scalable.
1.6.2. Git for source control
1.6.3. Hosting with Heroku 1.4.1. Relational databases vs. document stores
1.7. Putting it together with a practical
example If you’ve used a relational database before, or even a spreadsheet, you’ll b
1.7.1. Introducing the example application
used to the concepts of columns and rows. Typically, a column defines the
1.7.2. How the MEAN stack components
name and data type, and each row is a different entry. See table 1.1 for an
work together example.
Ch 2 Designing a MEAN stack architecture
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 14/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
now
1.3. Introducing Express: The frameworkTable 1.2. Each document in a document database defines and holds the
1.3.1. Easing your server setup data, in no particular order.
1.3.2. Routing URLs to responses
firstName: middleName: lastName:
1.3.3. Views: HTML responses nickname: "Si"
"Simon" "David" "Holmes"
1.3.4. Remembering visitors with session
lastName: middleName: firstName:
support
"Panayiotou" "June" "Sally"
1.4. Introducing MongoDB: The databasemaidenName: firstName: lastName: nickname:
1.4.1. Relational databases vs. document
"Holmes" "Rebecca" "Norman" "Bec"
stores
1.4.2. MongoDB documents: JavaScript
data store
1.4.3. More than just a document database
This less-structured approach means that a collection of documents could
1.4.4. What is MongoDB not good for?
have a wide variety of data inside. In the next section, you’ll look at a
1.4.5. Mongoose for data modeling sample
and document to get a better idea of what we’re talking about.
more
1.5. Introducing Angular: The front-end
framework 1.4.2. MongoDB documents: JavaScript data store
1.5.1. jQuery vs. Angular
MongoDB stores documents as BSON, which is binary JSON (JavaScript
1.5.2. Two-way data binding: Working with
Serialized Object Notation). Don’t worry for now if you’re not fully familia
data in a page
with JSON; check out the relevant section in appendix D. In short, JSON is
1.5.3. Using Angular to load new pages
JavaScript way of holding data, which is why MongoDB fits so well into th
1.5.4. Are there any downsides?
JavaScript-centric MEAN stack!
1.5.5. Developing in TypeScript
1.6. Supporting cast
The following code snippet shows a simple example MongoDB document:
1.6.1. Twitter Bootstrap for user interface
1.6.2. Git for source control
1.6.3. Hosting with Heroku {
"firstName" : "Simon",
}
1.7.1. Introducing the example application
1.7.2. How the MEAN stack components
copy
work together
Even if you don’t know JSON well, you can probably see that this documen
stores the first and last names of Simon Holmes. Rather than a document
holding a data set that corresponds to a set of columns, a document holds
name/value pairs, which makes a document useful in its own right becaus
it both describes and defines the data.
A quick word about _ id : You most likely noticed the _ id entry alongsid
the names in the preceding example MongoDB document. The _ id entity
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 15/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
table of contents index look at MongoDB documents in more detail in chapter 5, when you
You’ll
1.2.1. JavaScript: The single language
start to add data to your application.
through the stack
1.2.2. Fast, efficient, and scalable
1.4.3. More than just a document database buy
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 16/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
livebook features:
discuss
Ask a question, share an example, or respond to another reader. Start a thread by selecting any
piece of text and clicking the discussion icon.
You could use Node.js, Express, and MongoDB to build a fully functioning
1.2.3. Using prebuilt packages via npm now
data-driven web application, and you’ll do that in this book. But you can
1.3. Introducing Express: The framework
1.3.1. Easing your server setup put some icing on the cake by adding Angular to the stack.
1.3.2. Routing URLs to responses
1.3.3. Views: HTML responses The traditional way of doing things is to have all data processing and
application logic on the server, which then passes HTML to the browser.
1.3.4. Remembering visitors with session
support Angular enables you to move some or all of this processing and logic to the
1.4. Introducing MongoDB: The database browser, often leaving the server passing data from the database. We’ll ta
1.4.1. Relational databases vs. document
a look at this process in a moment when we discuss data binding, but first
stores
we need to address the question of whether Angular is like jQuery, the
1.4.2. MongoDB documents: JavaScript
leading front-end JavaScript library.
data store
1.4.3. More than just a document database
1.5.1. jQuery vs. Angular
1.4.4. What is MongoDB not good for?
1.4.5. Mongoose for data modeling If
and
you’re familiar with jQuery, you may be wondering whether Angular
more
works the same way. The short answer is no, not really. jQuery is generally
1.5. Introducing Angular: The front-end
added to a page to provide interactivity after the HTML has been sent to th
framework
1.5.1. jQuery vs. Angular browser and the Document Object Model (DOM) has completely loaded.
Angular comes in a step earlier, building the HTML from templates, based
1.5.2. Two-way data binding: Working with
data in a page on the data provided.
1.5.3. Using Angular to load new pages
1.5.4. Are there any downsides? Also, jQuery is a library and as such has a collection of features that you ca
1.5.5. Developing in TypeScript use as you wish. Angular is known as an opinionated framework, which
1.6. Supporting cast means that it forces its opinion on you as to how it needs to be used. It also
abstracts away some of the underlying complexity, simplifying the
1.6.1. Twitter Bootstrap for user interface
1.6.2. Git for source control development experience.
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 18/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
1.4. Introducing MongoDB: The database steps 1 and 2 without writing a single line of JavaScript code! That’s right—
it’s all done with Angular’s two-way data binding ... and a bit of help from
1.4.1. Relational databases vs. document
stores some other Angular features.
1.4.2. MongoDB documents: JavaScript
data store
As you go through part 3 of the book, you’ll get to see—and use—this in
1.4.3. More than just a document database
action. Seeing is believing with this feature, and you won’t be disappointe
1.4.4. What is MongoDB not good for?
1.4.5. Mongoose for data modeling and
1.5.3. Using Angular to load new pages
more
1.5. Introducing Angular: The front-end
One thing that Angular was specifically designed for is single-page
framework
application (SPA) functionality. In real terms, an SPA runs everything insid
1.5.1. jQuery vs. Angular
the browser and never does a full page reload. All application logic, data
1.5.2. Two-way data binding: Working with
processing, user flow, and template delivery can be managed in the
data in a page
browser.
1.5.3. Using Angular to load new pages
1.5.4. Are there any downsides?
Think Gmail. That’s an SPA. Different views get shown in the page, along
1.5.5. Developing in TypeScript
with a variety of data sets, but the page itself never fully reloads.
1.6. Supporting cast
1.6.1. Twitter Bootstrap for user interface
1.6.2. Git for source control This approach can reduce the amount of resources you need on your serve
because you’re essentially crowdsourcing the computational power. Each
1.6.3. Hosting with Heroku
person’s browser is doing the hard work; your server is serving up static
1.7. Putting it together with a practical
example files and data on request.
1.7.1. Introducing the example application
The user experience can also be better under this approach. After the
1.7.2. How the MEAN stack components
work together application is loaded, fewer calls are made to the server, reducing the
potential of latency.
Ch 2 Designing a MEAN stack architecture
All this sounds great, but surely there’s a price to pay. Why isn’t everythin
built into Angular?
Despite its many benefits, Angular isn’t appropriate for every website.
Front-end libraries like jQuery are best used for progressive enhancement
The idea is that your site will function perfectly well without JavaScript,
and the JavaScript you use makes the experience better. That isn’t the case
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 19/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
with Angular or indeed with any other SPA framework. Angular uses
JavaScript to build the rendered HTML from templates and data, so if your
browser doesn’t support JavaScript or there’s a bug in the code, the site
table of contents won’t
index run.
1.2.1. JavaScript: The single language
through the stack JavaScript to build the page also causes problems with
This reliance on
1.2.2. Fast, efficient, and scalable
search engines. When a search engine crawls your site, it won’t run all
1.2.3. Using prebuilt packages via npm buy
JavaScript; with Angular, the only thing you get before JavaScript takes
now
1.3. Introducing Express: The framework over is the base template from the server. If you want to be 100% certain
1.3.1. Easing your server setup
that your content and data are indexed by search engines rather than only
1.3.2. Routing URLs to responses your templates, you need to think about whether Angular is right for that
1.3.3. Views: HTML responses project.
1.3.4. Remembering visitors with session
support
You have ways to combat this issue: in short, you need your server to
1.4. Introducing MongoDB: The database
output compiled content as well as Angular. But, if you don’t need to fight
1.4.1. Relational databases vs. document
stores this battle, we recommend against doing so.
livebook features:
settings
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 20/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
Update your profile, view your dashboard, tweak the text size, or turn on dark mode.
view how
Bootstrap comes with a set of predefined CSS classes that can create usefu
visual components, such as page headers, alert-message containers, label
and badges, and stylized lists. The creators of Bootstrap put a lot of though
into the framework. Bootstrap helps you build an application quickly
without having to spend too much time on the HTML layout and CSS
styling.
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 21/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
Teaching Bootstrap isn’t an aim of this book, but we’ll point out various
features as you use them.
now
Fortunately, you can download themes for Bootstrap to give your
1.3. Introducing Express: The framework
1.3.1. Easing your server setup application a different twist. Downloading a theme is often as simple as
replacing the Bootstrap CSS file with a new one. You’ll use a free theme in
1.3.2. Routing URLs to responses
this book to build your application, but it’s also possible to buy premium
1.3.3. Views: HTML responses
themes from several websites to give an application a unique feel.
1.3.4. Remembering visitors with session
support
1.4. Introducing MongoDB: The database 1.6.2. Git for source control
1.4.1. Relational databases vs. document
stores Saving code on your computer or a network drive is all very well and good
but a computer or network drive holds only the current version and lets
1.4.2. MongoDB documents: JavaScript
data store only you (or other users on your network) access it.
1.4.3. More than just a document database
1.4.4. What is MongoDB not good for?
Git is a distributed revision control and source code management system
1.4.5. Mongoose for data modeling that
and allows several people to work on the same codebase at the same time
more on different computers and networks. These can be pushed together, with
1.5. Introducing Angular: The front-end
all changes stored and recorded. It’s also possible to roll back to an earlier
framework
state if necessary.
1.5.1. jQuery vs. Angular
1.5.2. Two-way data binding: Working with
data in a page How to use Git
1.5.3. Using Angular to load new pages
1.5.4. Are there any downsides? Git is typically used from the command line, although GUIs are available
1.5.5. Developing in TypeScript for Windows, Linux, and Mac. Throughout this book, you’ll use command
1.6. Supporting cast line statements to issue the commands that you need. Git is powerful, and
we’ll scratch the surface of it in this book, but everything we do will be
1.6.1. Twitter Bootstrap for user interface
1.6.2. Git for source control provided as part of the examples.
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 22/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
now
1.3. Introducing Express: The frameworkin Node.js. Some providers install it for you so that you can run
1.3.1. Easing your server setup applications, but the servers generally aren’t set up to meet the unique
1.3.2. Routing URLs to responses needs of Node.js. To run a Node.js application successfully, you need a
1.3.3. Views: HTML responses server that has been configured with it in mind, or you can use a PaaS
provider that’s specifically designed for hosting Node.js.
1.3.4. Remembering visitors with session
support
1.4. Introducing MongoDB: The database In this book, you’ll take the latter approach. You’ll use Heroku
1.4.1. Relational databases vs. document
(https://www.heroku.com) as your hosting provider. Heroku is one of the
stores leading hosts of Node.js applications and it has an excellent free tier that
1.4.2. MongoDB documents: JavaScript
you’ll make use of.
data store
1.4.3. More than just a document database
Applications on Heroku are essentially Git repositories, making the
1.4.4. What is MongoDB not good for?
publishing process incredibly simple. After everything is set up, you can
1.4.5. Mongoose for data modeling and
more publish your application to a live environment by using a single command
So what are you going to be building as you go through the book? You’ll be
building an application called Loc8r. Loc8r lists nearby places with Wi-Fi
where people can go to get some work done. It also displays facilities,
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 23/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
opening times, a rating, and a location map for each place. Users will be
able to log in and submit ratings and reviews.
table of contents indexapplication has some grounding in the real world. Location-based
This
1.2.1. JavaScript: The single language
applications themselves aren’t particularly new and come in a few guises.
through the stack
Swarm and Facebook Check In list everything nearby that they can and
1.2.2. Fast, efficient, and scalable
crowdsource data for new places and information updates. Urbanspoon
1.2.3. Using prebuilt packages via npm buy
helps people find nearby places to eat, allowing a user to search on price
now
1.3. Introducing Express: The framework bracket and type of cuisine. Even companies like Starbucks and McDonald
1.3.1. Easing your server setup
have sections of their applications that help users find the nearest one.
1.3.2. Routing URLs to responses
1.3.3. Views: HTML responses
Real or fake data?
1.3.4. Remembering visitors with session
support
Okay, we’re going to fake the data for Loc8r in this book, but you could
1.4. Introducing MongoDB: The database
collate the data, crowdsource it, or use an external source if you wanted to
1.4.1. Relational databases vs. document
stores For a rapid prototype approach, you’ll often find that faking data for the
first private version of your application speeds the process.
1.4.2. MongoDB documents: JavaScript
data store
1.4.3. More than just a document database
End product
1.4.4. What is MongoDB not good for?
1.4.5. Mongoose for data modeling You’ll
and use all layers of the MEAN stack to create Loc8r, including Twitter
more
Bootstrap to help you create a responsive layout. Figure 1.7 shows some
1.5. Introducing Angular: The front-end
screenshots of what you’ll build throughout the book.
framework
1.5.1. jQuery vs. Angular
1.5.2. Two-way data binding: Working with
data in a page Figure 1.7. Loc8r is the application you’ll build throughout this book. It
displays differently on different devices, showing a list of places and
1.5.3. Using Angular to load new pages
details about each place, and allows visitors to log in and leave reviews
1.5.4. Are there any downsides?
1.5.5. Developing in TypeScript
1.6. Supporting cast
1.6.1. Twitter Bootstrap for user interface
1.6.2. Git for source control
1.6.3. Hosting with Heroku
1.7. Putting it together with a practical
example
1.7.1. Introducing the example application
1.7.2. How the MEAN stack components
work together
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 24/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
now
1.3. Introducing Express: The framework
1.3.1. Easing your server setup
1.3.2. Routing URLs to responses
1.3.3. Views: HTML responses
1.3.4. Remembering visitors with session
support
1.4. Introducing MongoDB: The database
1.4.1. Relational databases vs. document
stores
1.4.2. MongoDB documents: JavaScript
data store
1.4.3. More than just a document database
1.4.4. What is MongoDB not good for?
1.4.5. Mongoose for data modeling and
more
1.5. Introducing Angular: The front-end
framework
1.5.1. jQuery vs. Angular
1.5.2. Two-way data binding: Working with
data in a page 1.7.2. How the MEAN stack components work together
1.5.3. Using Angular to load new pages
By the time you’ve been through this book, you’ll have an application
1.5.4. Are there any downsides? running on the MEAN stack, using JavaScript all the way through.
1.5.5. Developing in TypeScript MongoDB stores data in binary JSON, which, through Mongoose, is expose
1.6. Supporting cast as JSON. The Express framework sits on top of Node.js, where the code is
1.6.1. Twitter Bootstrap for user interface
written in JavaScript. In the front end is Angular, which is TypeScript.
1.6.2. Git for source control Figure 1.8 illustrates this flow and connection.
1.6.3. Hosting with Heroku
1.7. Putting it together with a practical
example Figure 1.8. JavaScript (partly as TypeScript) is the common language
throughout the MEAN stack, and JSON is the common data format.
1.7.1. Introducing the example application
1.7.2. How the MEAN stack components
work together
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 25/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
now
1.3. Introducing Express: The framework
1.3.1. Easing your server setup
1.3.2. Routing URLs to responses
1.3.3. Views: HTML responses
1.3.4. Remembering visitors with session
support
1.4. Introducing MongoDB: The database
1.4.1. Relational databases vs. document
stores
1.4.2. MongoDB documents: JavaScript
data store
1.4.3. More than just a document database
1.4.4. What is MongoDB not good for?
1.4.5. Mongoose for data modeling and
more
We’ll explore various ways that you can architect the MEAN stack and how
1.5. Introducing Angular: The front-end
framework you’ll build Loc8r in chapter 2.
1.5.1. jQuery vs. Angular
Because
1.5.2. Two-way data binding: Working with JavaScript plays such a pivotal role in the stack, please take a look
data in a page at appendix D (available online and in the e-book), which has a refresher
1.5.3. Using Angular to load new pages
on JavaScript pitfalls and best practices.
1.5.4. Are there any downsides?
1.5.5. Developing in TypeScript
Summary
1.6. Supporting cast
1.6.1. Twitter Bootstrap for user interface
In this chapter, you learned
1.6.2. Git for source control
1.6.3. Hosting with Heroku Which technologies make up the MEAN stack and how they work
1.7. Putting it together with a practical together
example Where MongoDB fits as the data layer
1.7.1. Introducing the example application
How Node.js and Express work together to provide an application
1.7.2. How the MEAN stack components server layer
work together How Angular provides an amazing front-end, data-binding layer
Ch 2 Designing a MEAN stack architecture A fewways to extend the MEAN stack with additional
technologies
sitemap
Up next...
Chapter 2. Designing a MEAN stack architecture
Introducing a common MEAN stack architecture
Single-page applications
Discovering alternative MEAN stack architectures
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 26/27
4/12/22, 1:53 AM Chapter 1. Introducing full-stack development - Getting MEAN with Mongo, Express, Angular, and Node.js 2ED
now
1.3. Introducing Express: The framework
1.3.1. Easing your server setup
1.3.2. Routing URLs to responses
1.3.3. Views: HTML responses
1.3.4. Remembering visitors with session
support
1.4. Introducing MongoDB: The database
1.4.1. Relational databases vs. document
stores
1.4.2. MongoDB documents: JavaScript
data store
1.4.3. More than just a document database
1.4.4. What is MongoDB not good for?
1.4.5. Mongoose for data modeling and
more
1.5. Introducing Angular: The front-end
framework
1.5.1. jQuery vs. Angular
1.5.2. Two-way data binding: Working with
data in a page
1.5.3. Using Angular to load new pages
1.5.4. Are there any downsides?
1.5.5. Developing in TypeScript
1.6. Supporting cast
1.6.1. Twitter Bootstrap for user interface
1.6.2. Git for source control
1.6.3. Hosting with Heroku
1.7. Putting it together with a practical
example
1.7.1. Introducing the example application
1.7.2. How the MEAN stack components
work together
https://livebook.manning.com/book/getting-mean-with-mongo-express-angular-and-node-second-edition/chapter-1/107 27/27