Book Image

Node.js 6.x Blueprints

By : Fernando Monteiro
Book Image

Node.js 6.x Blueprints

By: Fernando Monteiro

Overview of this book

Node.js is the most popular framework to create server-side applications today. Be it web, desktop, or mobile, Node.js comes to your rescue to create stunning real-time applications. Node.js 6.x Blueprints will teach you to build these types of projects in an easy-to-understand manner. The key to any Node.js project is a strong foundation on the concepts that will be a part of every project. The book will first teach you the MVC design pattern while developing a Twitter-like application using Express.js. In the next chapters, you will learn to create a website and applications such as streaming, photography, and a store locator using MongoDB, MySQL, and Firebase. Once you’re warmed up, we’ll move on to more complex projects such as a consumer feedback app, a real-time chat app, and a blog using Node.js with frameworks such as loopback.io and socket.io. Finally, we’ll explore front-end build processes, Docker, and continuous delivery. By the end of book, you will be comfortable working with Node.js applications and will know the best tools and frameworks to build highly scalable desktop and cloud applications.
Table of Contents (16 chapters)
Node.js 6.x Blueprints
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

Preface

Web applications with Node.js are increasingly popular and accessible to all developers. Today, with the growing evolution of Node.js, we can see numerous companies using this technology for the development of their applications. Among them, we can mention Netflix, Paypal, and many others who use Node.js in production environments.

The hosting companies also made a breakthrough by supporting Node.js on their platforms. Plus, many building tools, such as task runners, generators and dependence managers, emerged using the Node.js engine, such as Grunt, Gulp, Bower, and more.

Throughout the book, we will show you how to build and deploy Node.js applications from scratch by using all the resources available on the Node.js ecosystem and exploring cloud services for testing, image manipulation, and deployment.

Dealing with all these tools and getting the best out of them all is a very interesting and motivating task.

We will also introduce the concept of Docker containers and continuous integration using different tools and services.

Over the course of our book, we will see how to get the best out of this development method using the latest and greatest technologies to build ten applications from start to end.

Enjoy!

What this book covers

Throughout this book, we'll explore different ways to build Node.js Applications and understand what elements make up a basic blog page using MVC design patterns. We will learn how to deal with different types of view templates such as EJS and SWIG and more complex stuff using command-line tools to deploy and run applications.

We will cover fundamental concepts of the Restful API architecture and client-side communication using jQuery, React.js and Angular.js.

Although some points are advanced, you'll be prepared to understand the core concepts of Node.js applications, and how to deal with different types of database's such as MongoDB, MySQL, and the Express and Loopback frameworks.

Chapter 1 , Building a Twitter-Like Application Using MVC Design Patterns, shows the main concepts of the MVC pattern applied to Node.js applications using the Express framework, mongoose ODM middleware, and MongoDB database. We see how to deal with user sessions and authentication using Passport middleware.

Chapter 2 , Building a Basic Website Using MySQL Database, is a real dive into a Node.js application using a relational database. We see how to use the Sequelize (ORM)  middleware with Mysql database, how to create database relationships, and how to use migration files.

Chapter 3 , Building a Multimedia Application, teaches you how to deal with file storage and upload multimedia files such as images and videos. We also see how to save filenames on MongoDB and how to retrieve the files and show them on user interface. Then we learn how to deal with write and read using the Node.js streams API.

Chapter 4 , Don't Take a Photograph, Make It – An App for Photographers, covers an application to upload, store, and manipulate images using the Cloudnary cloud services, and interacting with MongoDB. Also, we will see how to implement the Materialize.css framework for the user interface, and introduce the use of dot files to load configuration variable.

Chapter 5 , Creating a Store Locator Application with MongoDB Geospatial Query, explains the core concepts of geospatial data and geolocation using MongoDB, and one of the most useful features to support GEOJSON data format, the 2dspheres indexes. You will understand how to integrate Google Maps API with a Node.js application.

Chapter 6 , Building a Customer Feedback App with Restful API and Loopback.io, explores the loopback.io framework to build a Restful API. We will see the fundamentals of the Loopback CLI in order to create an entire application using the command line. You'll learn how to deal with the relationship between models using MongoDB and how to use React.js on the client side to communicate with the API.

Chapter 7 , Building a Real-Time Chat Application with Socket.io, shows the fundamentals of Socket.io events to build a chat application using Express and jQuery for the user interface. It covers the basic concept of task managers and how to use Gulp and livereload plugin.

Chapter 8 , Creating a Blog with Keystone CMS, discusses the use of a CMS made entirely with Node.js, called Keystone. It's a deep dive into the Keystone application structure and how to extend the framework in order to create new models and views. Also, we will see how to customize and create new Keystone themes.

Chapter 9 , Building a Frontend Process with Node.js and NPM, is especially interesting because we will create a Restful application using the loopback.io framework and AngularJS for the user interface. Also, we will use different building tools to concatenate, minify, and optimize images using the command line and Node Package Manager (NPM). And we will see how to use the Heroku toolbelt CLI to create and deploy the application.

Chapter 10 , Creating and Deploying Using Continuous Integration and Docker, explores the continuous delivery development process with Node.js applications. You will learn how to integrate tools such as Github, Codeship, and Heroku into your development environment to deal with unit tests and automated deployment. This chpater also teaches you how to set up environment variables to protect your database credentials and how to create a full application using the concept of Docker containers.

What you need for this book

All the examples in the book use open source solutions and can be downloaded for free from the links provided in each chapter.

The book's examples use many Node.js modules and some JavaScript libraries, such as jQuery, React.js, and AngularJS. The most current versions when writing this book are Node.js 5.6 and 6.1.

In chapter 1, Building a Twitter-Like Application Using the MVC Design Pattern, you can follow the step-by-step guide to install Node and Node Package Manager (NPM).

You can use your preferred HTML editor.

A modern browser will be very helpful too. We've used  Chrome, but feel free to use your preference. We recommend one of these: Safari, Firefox, Chrome, IE, or Opera, all in their latest versions.

Who this book is for

You must have basic to intermediate knowledge of JavaScript, HTML, and CSS to follow the examples in the book, but slightly more advanced knowledge in web development/Restful APIs and Node.js modules/middleware may be required in some chapters. Do not worry about it; with the examples, we will detail all of the code and give you a lot of links to interesting stuff.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows:

Before we proceed, let's change the welcome message from: routes/index.js file to the following highlighted code.

A block of code is set as follows:

/* GET home page. */
router.get('/', function(req, res, next) {
    res.render('index', { title: 'Express from server folder' });
});

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

/* GET home page. */
router.get('/', function(req, res, next) {
    res.render('index', { title: 'Express from server folder' });
});

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "clicking on the Next button moves you to the next screen".

Warnings or important notes appear in a box like this.

Tips and tricks appear like this.

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book 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.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.

  2. Hover the mouse pointer on the SUPPORT tab at the top.

  3. Click on Code Downloads & Errata.

  4. Enter the name of the book in the Search box.

  5. Select the book for which you're looking to download the code files.

  6. Choose from the drop-down menu where you purchased this book from.

  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows

  • Zipeg / iZip / UnRarX for Mac

  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Node.JS-6.x-Blueprints. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.