Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Mongoose for Application Development
Mongoose for Application Development

Mongoose for Application Development: Mongoose streamlines application development on the Node.js stack and this book is the ideal guide to both the concepts and practical application. From connecting to a database to re-usable plugins, it's all here.

eBook
€17.99 €25.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Mongoose for Application Development

Chapter 1. Introducing Mongoose to the Technology Stack

We are going to take a look at the technology stack we'll be using throughout the book. After a brief discussion of Node, npm, MongoDB, and Express we will introduce Mongoose as an ODM (Object-Document Modeler), cover good and bad use cases, and introduce the two cornerstones of Mongoose.

By the end of this chapter you will have an understanding of the technology stack and where Mongoose fits in. We will also have set up the sample project that we will build throughout the book.

The technology stack – Node.js, npm, MongoDB, and Express


The benefits of Node are making it ever more popular, and a set of compatible technologies are fast becoming the basis of a new standard development stack.

The language and the server – JavaScript and Node

For quite some time JavaScript was mainly thought of as a lightweight browser-based scripting language. Microsoft did support a JavaScript version of Classic ASP, but it was largely side-lined in favor of the VBScript version.

Fast-forward 10 years and there were some pretty impressive JavaScript-based apps on the Web, for example Gmail. The general view of JavaScript as a programming language was starting to change back then.

In 2010 a new server-side system called Node.js was starting to make waves in the Internet developer community. Node.js was a new way for using JavaScript on the server side again. And it was quick and efficient. It could make scaling a web application much more cost-effective by reducing the amount of hardware required per-site visitor or request.

By 2012 Node was one of the buzzwords of the start-up scene, and you can see why. Firstly, most Web developers have some JavaScript experience so it doesn't require you to learn a new language from scratch. This also means you can share some code between front-end and back-end, so you don't have to code the same thing twice in two different languages. An excellent example of this is form validation; you want real-time validation in the browser for a better user experience, but you also need to validate on the server side to protect your system. So you code the same thing twice. Using Node you can use the same validation script on the server side and the browser, so you only have to code it once, in JavaScript.

Second, there is the reduced cost of scaling, especially when dealing with large numbers of concurrent users. On the same hardware Node's efficiencies allow it to handle many more requests than classic stacks on Apache or IIS. That being said, adding scalability to Node is more complicated than other stacks. Unlike the others you can't just put it on a more powerful machine and set it running. By default Node will currently only run one process, using only one core of a machine. There are methods to address this issue, using a load balancer in front of several processes running alongside each other for example, and there are plans to enable future versions of Node to be able to manage this natively, directly addressing this issue.

The benefits of scalability do have a cost. The single process is a more complicated approach to server-side programming and requires a change in mindset.

Single-threaded versus multithreaded

Traditional stacks are generally multithreaded. This means that every new visitor or session is given a new thread, and these are never shared. One session's activity generally doesn't impact another, until the server resources are exhausted. For example, if Session 1 is doing a complex database write operation it may take a couple of seconds, but Session 2 continues running oblivious to this.

Node is single-threaded. This means that every visitor or session is added to that one thread. So it is possible for a two-second database write operation to hold up every other user for two seconds. Multiply this by just 10 users and you've got a big problem on your hands.

Addressing this requires a different way of coding.

Blocking versus non-blocking code

In the traditional stack, the approach to coding would be one step after the other, as in the following steps:

  1. First, take the data.

  2. Then write this data to the database.

  3. Send a confirmation message.

  4. Wait for the next request.

This is blocking code, as you can only do one thing at a time. This is fine in the multithreaded stack, as you're only ever responding to one person's requests.

In the single-threaded stack, you may have to respond to several people's requests at the same time, so you can't afford to be stuck doing time-consuming operations or waiting for someone else to do something. To do this, the approach to coding becomes more like the following:

  1. You give this data to someone.

  2. They write this data to the database.

  3. When they are done, they send a confirmation message; if this isn't something they can do, then they add it to your request list.

  4. You're going to take the next request.

This is non-blocking code. You can only do one at a time. So you're getting someone else to do something for you, and telling them what to do when they have finished. You can then deal with the next request coming in without any delay.

JavaScript callbacks

The way to code this in JavaScript is to use callbacks. Most JavaScript coders start using them before they even know it, particularly anybody who uses libraries such as jQuery.

Take the basic jQuery document.ready method as shown in the following:

$(document).ready(function() {
  console.log("document ready");
});

This is an event driven callback. The $(document).ready() part is a method function of jQuery, and we are sending it a function function() that it can run at the appropriate time. So we are saying "Hi ready, here is what I want you to do once the document is ready, I'll leave it up to you to decide when that is". The callback function we are using in this example is the following code snippet:

function() {
  console.log("document ready");
}
Running the callback

The jQuery .ready() function is pretty complicated, so we're not going to look at that here. However, the construct is very useful to understand. Look at the following code snippet:

ready = function (callback) {
  // do something
  // do something else
  // ....
  // and so on
  callback();
};

So ready itself is a function, and this function accepts one parameter callback. The callback parameter is generally an anonymous function, like the one we looked at earlier. A very important point to note is that callback now exists in the scope of the ready function. This means that your callback function has access to any variables or objects created in the ready function.

A Node.js example

Now consider the following standard Node "hello world" example:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {
    'Content-Type': 'text/plain'
  });
  res.write('Hello world');
res.end();
})
listen(8888, '127.0.0.1');

Look familiar? This is sending a callback to the http.createServer method function. See how the parameters—req and res—are being sent to the callback function even though they haven't been defined or created anywhere. This works because the http.createServer function will create these objects before calling this callback function that will use them.

The database – MongoDB

MongoDB has become the main database of choice for working with Node. Note that there are Node drivers for many other databases, including MySQL, Microsoft SQL Server, Reddis, PostgreSQL, CouchDB, and more.

MongoDB is popular as it is fast and flexible with excellent community support. It is a document-oriented database, fitting in somewhere between Key-Value stores and traditional relational databases. Despite being a document store, MongoDB also enables rich querying and secondary indexing of documents, setting it apart from other databases and making it a very powerful option.

MongoDB stores documents as BSON, which is effectively binary-encoded JSON. When you run a query you get a JSON object returned (or a string in JSON format, depending on the driver). Look at the following code snippet for example:

{ "_id" : ObjectId("4ffbc45c35097b5a1583ad71"), "firstname" : "Simon", "lastname" : "Holmes }

So, a document is a set of keys (for example, firstname) and values (for example, Simon). The _id entry is a unique identifier that the underlying MongoDB driver will—by default—create for each new document.

If you are more experienced with relational databases, it may help you to think of a document as a bit like a row in a table. In this analogy, the key can be thought of as a column. An important difference is that each document doesn't have to contain the exact same set of keys, and there is no direct need to have keys with empty values taking up space.

A collection of documents is called a collection. The closest analogy is a table. So in your database you could well have multiple collections, such as a users collection, posts collection, and stats collection.

MongoDB is also extremely scalable, with many built-in capabilities for distributing across multiple servers, without compromising speed or data integrity.

With everything combined, it makes MongoDB a great playmate for Node.

The framework – Express

Express is a web application framework for Node.

When you create a Node project, you have to do a lot more groundwork than you might be used to. Until you create it, there isn't even a web server. Then you have to deal with serving static files in a non-blocking way, figure out the routing mechanism, view engine, session management, and so on.

Or you can create an Express project and let it do all of this for you, in a tried-and-tested way. At the end of this chapter, we'll see how easy it is to set up an Express project.

Note that Express is not required to build a Node application, but it is a great starting point for building web applications.

What Mongoose is all about


Mongoose is an object modeling tool for MongoDB and Node.js. What this means in practical terms is that you can define your data model in just one place, in your code.

Yes, that's right. You don't have to create a schema in the database, link that to an ORM or map it into your project objects and classes. You can just define your data structure in JSON inside your project.

The first time I created a project like this I was amazed at how much time and frustration it saves. Even now I still get that warm glow when I start a new project or prototype using Mongoose. It's like taking a shortcut to work down deserted country lanes while everybody else is gridlocked on the highway.

A schema definition can be as simple as the following code snippet:

var userSchema = new mongoose.Schema({
  firstname: String,
  lastname: String,
  createdOn: Date
});

A document in MongoDB created from this schema would be like the following code snippet:

{ "__v" : 0, "_id" : ObjectId("51412597e8e6d3e35c000001"),"createdOn" : ISODate("2013-03-14T01:19:19.866Z"),"firstname" : "Simon", " lastname " : "Holmes" }

If you want to refactor, then you can just do it from within your code, saving a huge amount of development time.

What is Mongoose good for?

Mongoose is primarily useful when you want to interact with structured data in MongoDB. It allows you to define a schema for your data, so that you can interact with your MongoDB data in a structured and repeatable way.

Mongoose helps with many common MongoDB tasks, and removes some of levels of complexity from the nested callbacks you find yourself getting lost in with the native MongoDB driver.

Mongoose also returns the data to you as a JSON object that you can use directly, rather than the JSON string returned by MongoDB.

Mongoose also has a whole suite of helper functions and methods that we'll explore throughout the subsequent chapters of this book.

What Mongoose is not ideally suited for

Mongoose is probably not the answer for you if you are primarily working with the following:

  • Schema-less data

  • Random documents

  • Pure Key-Value pairs

The cornerstones of Mongoose

There are two aspects of Mongoose that we need to introduce you to before going much further:

  • Schemas

  • Models

This is a very high-level view; so don't worry if you're not 100 percent confident with this just yet, as we'll be covering it in a lot more detail later in this book.

Mongoose schemas

As we saw earlier, a schema is fundamentally describing the data construct of a document. This schema defines the name of each item of data, and the type of data, whether it is a string, number, date, Boolean, and so on.

var userSchema = new mongoose.Schema({
  name: String,
  email: String,
  createdOn: Date,
  verified: Boolean
});

In most scenarios you would have one schema for each collection within the database.

Schemas are a powerful aspect of Mongoose, which can also be extended with helper functions and additional methods. But we'll describe more about that in a later chapter.

Mongoose models

A model is a compiled version of the schema. One instance of the model will map to one document in the database.

Creating a User instance based on the schema userSchema is a one line task:

var User = mongoose.model('User', userSchema);

It is the model that handles the reading, creating, updating, and deleting of documents.

Installing the full stack


Now that we know a little bit about the technology, it's time to get everything installed. What follows is not an in-depth installation tutorial, but covers the necessary steps to get everything installed on Ubuntu. The installation process is very similar on other Linux distributions and Mac OS X. For Windows users, Node and MongoDB have installation packages you can run, and after that everything else is pretty much the same.

Installing the prerequisites

Node needs a couple of things installed to run properly, Python and a C compiler. So let's make sure those are installed and up-to-date with a terminal command. I use the Ubuntu Advanced Packaging Tool (APT) to install most software, as it makes it this easy:

$ sudo apt-get install python-software-properties python g++ make

Installing Node.js

Again we'll use APT to install Node.js. As Node is actively developed and frequently updated, APT doesn't always have the latest build. The latest version on APT is currently several versions behind, so we will add the repository of one of the Node.js developers. This is also the approach recommended on the Node website nodejs.org.

$ sudo add-apt-repository ppa:chris-lea/node.js
$ sudo apt-get update
$ sudo apt-get install nodejs

If everything has gone smoothly then you should be able to check the installed version displayed in terminal using the following command:

$ node --version

You should be greeted with a message back in the terminal along the lines of v0.10.0.

Installing npm

npm is a package manager for Node, although npm does not actually stand for Node Package Manager. As of Node Version 0.6.3, npm is actually automatically installed when you install Node.

You can quickly check that this has been done by checking the version number on the terminal.

$ npm --version
1.1.23

If it is not there for some reason, simply install it with APT with the following command:

$ sudo apt-get install npm

Installing MongoDB

Again we're using APT here.

$ sudo apt-get install mongodb

In order to test MongoDB, we need to run it. You can do this by just typing mongodb into terminal, but I prefer to run it as a persistent service so that you don't have to restart it.

$ sudo service mongodb start

This should give you a confirmation message in terminal that the mongodb process is running.

Now to finally test that it has installed correctly we'll drop into the built-in MongoDB shell. In terminal, enter the following:

$ mongo

This should do three things:

  • Enter you into the MongoDB shell

  • Show you the version of the shell being used

  • Connect to the test database that comes with MongoDB

You should see something like the following screenshot:

Installing Express.js

Now we're starting to get into the Node-based applications. So those of you who are working on different operating systems can start paying attention again now. We are going to install Express using npm.

$ sudo npm install -g express

Note

See the -g flag there in the command line? This installs express globally, meaning that we can use it wherever we want.

Once again you can test the installation by checking the version number.

$ express --version

Installing Mongoose

Finally we get round to installing Mongoose!

There are two ways of installing Mongoose, both using npm. I recommend using the latter one.

Direct installation into project

If you're creating a quick test app, or will never have to move or publish the project elsewhere, you can use npm to install Mongoose directly into your project. Navigate to the root folder of your site or project in terminal and run the following command:

$ sudo npm install mongoose

Using project dependencies – package.json

Any Node project can have a package.json file, and any packages you install via npm will have one. This file is normally in the root of your project, and can contain various metadata, such as project name, description, version number, and authors. It also helps manage the project's dependencies.

If you ever need to move, copy, or distribute your project you will find this invaluable. The dependency management means that you are not forced to remember which versions of which modules you added to each particular project. It becomes even more necessary if you distribute it widely, as it removes any doubt from the end-user's mind as to what the project needed.

Before we get into creating one, the following code snippet is an example of a package.json file following code snippet that you might expect to see when you create a new project using Express.

{
  "name": "application-name",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node app"
  },
 "dependencies": {
  "express": "3.0.0rc5",
  "jade": "*"
 }
}

Note

The list of dependencies are: a specific version of express and the latest version of jade.

To install a specific version of Mongoose—which is the recommended approach, especially if you are going to distribute your project—you would update the dependencies section to look like the following code snippet:

"dependencies": {
  "express": "3.0.0rc5",
  "jade": "*",
  "mongoose": "3.6"
}

To install or update all of the dependencies listed in a package.json file, using terminal, you simply navigate to the folder containing the file and run the following command:

$ npm install

Creating a project

Now that we have the entire building blocks ready, let's set the foundations. Throughout this book, we are going to build a simple project management web app, called MongoosePM.

Let's start off by creating an Express project.

  1. In terminal, navigate to a relevant folder, for example, /MyWebsites in Linux, or C:\Users\Your Username\Documents\My Web Sites\ in Windows.

  2. Enter the following command:

    $ express --sessions mongoosepm
    

This will create a new folder called mongoosepm. Inside this folder it will create a new Express project. By default an Express project doesn't support user sessions; an Express project is essentially stateless. By adding the --sessions parameter in the command line we add session support to our project, so that we can follow a user from page to page without having to constantly re-authenticate.

After Express has finished doing its thing you'll be able to see a whole load of new files and folders within your mongoosepm folder. The intricacies of Express are beyond the scope of this book, which is one of the reasons we have mainly stuck with the default settings.

The next step is normally to install the dependencies, but first let's add Mongoose and Connect to the dependency list. So open up the package.json file in the root of the project and add a couple of lines to the dependencies hash.

For example, if your dependencies section looks like the following code snippet:

"dependencies": {
  "express": "3.0.0rc5",
  "jade": "*"
}

Then you change it with this (see the following code):

"dependencies": {
  "express": "3.0.0rc5",
  "jade": "*",
  "connect": "2.7.x",
  "mongoose": "3.6.x"
}

It is recommended that you don't "wildcard" the version for most modules, as there is no guarantee that code based on older versions will work on newer versions. Putting a wildcard in for the patch version like we have for Connect and Mongoose, is recommended as they should only be patch updates and be backwards compatible.

To install these dependencies, go to the mongoosepm folder in terminal and run the following command:

$ npm install

Once this has finished working, we should have a fully functional Express website to play with. Let's test it to make sure!

Run the following command from terminal:

$ node app

You should see the following confirmation message directly in terminal:

Express server listening on port 3000

So open up a web browser, and point it to http://localhost:3000. All being well, you should be presented with the default Express project landing page, as shown in the following screenshot:

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Summary


In this chapter we have taken a whirlwind tour of the technology stack, and installed the required programs, which are as follows:

  • Node.js

  • npm

  • MongoDB

  • Express

  • Mongoose

You should have at least a basic understanding of the majority of the stack. We're not going to be discussing in depth the workings of Node, MongoDB, and Express, but I will make sure to briefly describe any new concepts as we go.

In this first chapter, we have also created the framework for the project that we are going to build in later chapters. This is a website built on Node.js, using the Express framework. We have tested and seen this working in a browser.

In the next chapter, we will take a look at how to create Mongoose connections to database, and the best way to add a connection to our new project.

Left arrow icon Right arrow icon

Key benefits

  • Rapid application development with Mongoose on the Node.js stack
  • Use Mongoose to give structure and manageability to MongoDB data
  • Practical exampless on how to use Mongoose for CRUD operations
  • Provides a number of helpful tips and takes away the complexity of everyday MongoDB operations
  • Walks you through building a project management application using Mongoose, Node.js, MongoDB, and Express

Description

Mongoose is all about putting the data model where it should be: in your application. You can control everything from within your application in JavaScript, eliminating the need to work with the database or a separate management system. Mongoose for Application Development is a practical, hands-on guide that takes you from installing the technology stack through the steps of developing a web application. It covers the key features of Mongoose and how to use them to rapidly develop a Node.js and MongoDB application. This book introduces the full technology stack of Node.js, MongoDB, Express, and Mongoose. It will take you through the process of building an application on this stack with a focus on how Mongoose makes the process quicker and easier. You will see how Mongoose removes a layer of complexity when dealing with MongoDB whilst giving you more control over your data from your application. You will learn how to define schemas and models for your data in JavaScript. Using these schemas and models, you will learn how to build the cornerstone of any web application that will include CRUD operations (creating, reading, updating, and deleting data). If you want to learn how to build applications quickly and efficiently using Node.js, then Mongoose and this book are ideal for you. Using practical examples throughout, Mongoose for Application Development not only teaches you about the concepts of Mongoose, but walks through how to use them to build a real-life application.

Who is this book for?

This book is ideal for people who want to develop applications on the Node.js stack quickly and efficiently. Prior knowledge of the stack is not essential as the book briefly covers the installation of the core components and builds all aspects of the example application. The focus of the book is on what Mongoose adds to you applications, so experienced Node.js developers will also benefit.

What you will learn

  • Learn the different methods of using Mongoose to connect to a database
  • Learn to define schemas and building data models
  • Interact with data using schema methods
  • Create databases, collections, and data
  • Query the database to find specific data
  • Edit, save, and delete data
  • Validate data using Mongoose validators
  • Use population to link datasets
  • Use sub-documents and nested schemas to provide data depth
  • Get to grips with code efficiency through re-usable plugins
Estimated delivery fee Deliver to Czechia

Premium delivery 7 - 10 business days

€25.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Aug 26, 2013
Length: 142 pages
Edition : 1st
Language : English
ISBN-13 : 9781782168195
Category :
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Czechia

Premium delivery 7 - 10 business days

€25.95
(Includes tracking information)

Product Details

Publication date : Aug 26, 2013
Length: 142 pages
Edition : 1st
Language : English
ISBN-13 : 9781782168195
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 107.97
Express Web Application Development
€41.99
Mongoose for Application Development
€32.99
Advanced Express Web Application Development
€32.99
Total 107.97 Stars icon

Table of Contents

11 Chapters
Introducing Mongoose to the Technology Stack Chevron down icon Chevron up icon
Establishing a Database Connection Chevron down icon Chevron up icon
Schemas and Models Chevron down icon Chevron up icon
Interacting with Data – an Introduction Chevron down icon Chevron up icon
Interacting with Data – Creation Chevron down icon Chevron up icon
Interacting with Data – Reading, Querying, and Finding Chevron down icon Chevron up icon
Interacting with Data – Updating Chevron down icon Chevron up icon
Interacting with Data – Deleting Chevron down icon Chevron up icon
Validating Data Chevron down icon Chevron up icon
Complex Schemas Chevron down icon Chevron up icon
Plugins – Re-using Code Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2
(10 Ratings)
5 star 50%
4 star 20%
3 star 30%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Alex B Jul 14, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Amazing book. There are a lot of tips and tricks in there and if you use mongoose a lot you will actually find a lot of cool coding secrets and explanations to weird things that go on under the hood. Its a must read if you like Mongoose.
Amazon Verified review Amazon
CharlieBear Apr 30, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is an excellent book for anyone moving from C#/.NET or any other non-web based development platform. It is a great way to get a quick start if you want to jump onto the Javascript bandwagon and get ready for web apps that run and behave like Windows apps.The book covers everything you need to build a browser based application (or mobile apps too) with all code being Javascript. The examples are easy to follow and to the point, including the traditional CRUD application. Routes, Jade templates, JSON, AJAX, data validation and plugins are all also covered. It's just a good book to get started writing client and server side applications. Also covers a lot of the different methods for fetching and working with data. Mongoose has a "code first" database creation feature that is very cool.There is one problem due to changes made to Node.js launch for Express/Mongoose since the date of publication. I'd recommend skipping the getting started instructions in the book (chapter 1) and use this web site instead, especially if you are running with MS Windows:[...]I found the above URL after following the book's instructions, step-by-step (using Windows 7) and couldn't get Express to fire up. Other than that, I'd recommend using this book for anyone who wants to get started writing highly responsive web based/mobile applications.
Amazon Verified review Amazon
Robby May 07, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book helped me a lot. It's small, to the point. The code works. It got me up to speed. Good job
Amazon Verified review Amazon
Konstantin Sep 26, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I bought this book from the publishers site to help me get up to speed with using Mongoose, Node.js, MongoDB, and Express. I must say i am very impressed with it. The book is very well written, and the examples work as expected. (unlike other programming books you buy). The sample project in the book comes in very handy and teaches you how to build a CRUD like application using these technology stack. Note that the major focus on this book is mongoose! Though you get to understand how the other stack work, they are not in-depth. Mongoose however is cover pretty deeply.
Amazon Verified review Amazon
Eric Rabbath May 02, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is an excellent short book on using Mongoose to connect your MongoDB back-end database to your Node.js application. The explanations are very clear and to the point, and the examples given are always an excellent illustration of the point being discussed.The ongoing example is also well chosen, and well used to integrate the various concepts into a complete working application. It uses Express to build the application, and while the explanations in the book are very clear and complete, a basic understanding of the key concepts of the Express framework (routes, request, response objects) is useful to really understand what is going on.As mentioned by others, the installation instructions are a little out of date, but this can very easily be solved with a simple web search.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela