Getting MEAN with Mongo, Express, Angular, and Node

Total Page:16

File Type:pdf, Size:1020Kb

Getting MEAN with Mongo, Express, Angular, and Node SAMPLE CHAPTER MANNING Simon Holmes Getting MEAN with Mongo, Express, Angular, and Node by Simon Holmes Chapter 5 Copyright 2016 Manning Publications brief contents PART 1SETTING THE BASELINE .................................................1 1 ■ Introducing full-stack development 3 2 ■ Designing a MEAN stack architecture 24 PART 2BUILDING A NODE WEB APPLICATION...........................51 3 ■ Creating and setting up a MEAN project 53 4 ■ Building a static site with Node and Express 80 5 ■ Building a data model with MongoDB and Mongoose 120 6 ■ Writing a REST API: Exposing the MongoDB database to the application 160 7 ■ Consuming a REST API: Using an API from inside Express 202 PART 3ADDING A DYNAMIC FRONT END WITH ANGULAR.........241 8 ■ Adding Angular components to an Express application 243 v vi BRIEF CONTENTS 9 ■ Building a single-page application with Angular: Foundations 276 10 ■ Building an SPA with Angular: The next level 304 PART 4MANAGING AUTHENTICATION AND USER SESSIONS......347 11 ■ Authenticating users, managing sessions, and securing APIs 349 Building a data model with MongoDB and Mongoose This chapter covers ■ How Mongoose helps bridge an Express/Node application to a MongoDB database ■ Defining schemas for a data model using Mongoose ■ Connecting an application to a database ■ Managing databases using the MongoDB shell ■ Pushing a database into a live environment ■ Using the correct database depending on the environment, distinguishing between local and live versions of an application In chapter 4 we ended up by moving our data out of the views and backward down the MVC path into the controllers. Ultimately, the controllers will pass data to the views, but they shouldn’t store it. Figure 5.1 recaps the data flow in an MVC pattern. For storing the data we’ll need a database, specifically MongoDB. So this is our next step in the process: creating a database and data model. 120 Building a data model with MongoDB and Mongoose 121 Data flow in an MVC pattern Holds the Processes Renders the data the data processed data Model Controller View Data flow Data flow Figure 5.1 In an MVC pattern, data is held in the model, processed by a controller, and then rendered by a view. NOTE If you haven’t yet built the application from chapter 4, you can get the code from GitHub on the chapter-04 branch at github.com/simonholmes/ getting-MEAN. In a fresh folder in terminal the following command will clone it: $ git clone -b chapter-04 https://github.com/simonholmes/getting-MEAN.git We’ll start by connecting our application to a database before using Mongoose to define schemas and models. When we’re happy with the structure we can add some test data directly to the MongoDB database. The final step will be making sure that this also works when pushed up to Heroku. Figure 5.2 shows the flow of these four steps. 1 2 3 4 Connect Define Add test Push application schemas data to to live to database and models database environment Figure 5.2 Four main steps in this chapter, from connecting our application to a database to pushing the whole thing into a live environment For those of you who are worried that you’ve missed a section or two, don’t worry—we haven’t created a database yet. And we don’t need to. In various other technology stacks this can present an issue and throw errors. But with MongoDB we don’t need to create a database before connecting to it. MongoDB will create a database when we first try to use it. 122 CHAPTER 5 Building a data model with MongoDB and Mongoose 1 Use Mongoose with Express and Encapsulating Node.js to model Express app Express app data and connect to database Database API Express Node.js AngularJS MongoDB Express Angular SPA Node.js Figure 5.3 The MongoDB database 2 Create database and using Mongoose and add data to it inside Express to model the data and manage AngularJS the connection to the database Figure 5.3 shows where this chapter will focus in terms of the overall architecture. We’ll, of course, be working with a MongoDB database, but most of the work will be in Express and Node. In chapter 2 we discussed the benefits of decoupling the data integration by creating an API rather than tightly integrating it into the main Express app. So although we’ll be working in Express and Node, and still within the same encapsulating application, we’ll actually be starting the foundations of our API layer. NOTE To follow through this chapter you’ll need to have MongoDB installed. If you haven’t done so already, you can find the instructions for this in appen- dix A. The source code of the application as it will be at the end of this chapter is avail- able from GitHub on the chapter-05 branch. In a fresh folder in terminal the following commands will clone it and install the npm module dependencies: $ git clone -b chapter-05 https://github.com/simonholmes/getting-MEAN.git $ cd getting-MEAN $ npm install 5.1 Connecting the Express application to MongoDB using Mongoose We could connect our application directly to MongoDB and have the two interact with each other using the native driver. While the native MongoDB driver is very Connecting the Express application to MongoDB using Mongoose 123 powerful it isn’t particularly easy to work with. It also doesn’t offer a built-in way of defining and maintaining data structures. Mongoose exposes most of the function- ality of the native driver, but in a more convenient way, designed to fit into the flows of application development. Where Mongoose really excels is in the way it enables us to define data struc- tures and models, maintain them, and use them to interact with our database. All from the comfort of our application code. As part of this approach Mongoose includes the ability to add validation to our data definitions, meaning that we don’t have to write validation code into every place in our application where we send data back to the database. So Mongoose fits into the stack inside the Express application by being the liaison between the application and the database, as shown in figure 5.4. Browser Database Application application MongoDB Node.js AngularJS Express Mongoose Figure 5.4 The data interactions in the MEAN stack and where Mongoose fits in. The Node/Express application interacts with MongoDB through Mongoose, and Node and Express can then also talk to Angular. MongoDB only talks to Mongoose, and Mongoose in turn talks to Node and Express. Angular will not talk directly to MongoDB or Mongoose, but only to the Express application. You should already have MongoDB installed on your system (covered in appen- dix A), but not Mongoose. Mongoose isn’t installed globally, but is instead added directly to our application. We’ll do that now. 5.1.1 Adding Mongoose to our application Mongoose is available as an npm module. As you saw in chapter 3, the quickest and easiest way to install an npm module is through the command line. We can install Mongoose and add it to our list of dependencies in package.json with one command. So head over to terminal and make sure the prompt is at the root folder of the application, where the package.json file is, and run the following command: $ npm install --save mongoose 124 CHAPTER 5 Building a data model with MongoDB and Mongoose The --save flag is what tells npm to add Mongoose to the dependency list in pack- age.json. When that command has finished running you’ll be able to see a new mon- goose folder inside the node_modules folder of the application, and the dependencies section of the package.json file should look like the following code snippet: "dependencies": { "express": "~4.9.0", "body-parser": "~1.8.1", "cookie-parser": "~1.3.3", "morgan": "~1.3.0", "serve-favicon": "~2.1.3", "debug": "~2.0.0", "jade": "~1.6.0", "mongoose": "~3.8.20" } You may have slightly different version numbers, of course, but at the time of writing the latest stable version of Mongoose is 3.8.20. Now that Mongoose is installed, let’s get it connected. 5.1.2 Adding a Mongoose connection to our application At this stage we’re going to connect our application to a database. We haven’t created a database yet, but that doesn’t matter because MongoDB will create a database when we first try to use it. This can seem a little odd, but for putting an application together it’s a great advantage: we don’t need to leave our application code to mess around in a different environment. MONGODB AND MONGOOSE CONNECTION Mongoose opens a pool of five reusable connections when it connects to a MongoDB database. This pool of connections is shared between all requests. Five is just the default number and can be increased or decreased in the connection options if you need to. BEST-PRACTICE TIP Opening and closing connections to databases can take a little bit of time, especially if your database is on a separate server or service. So it’s best to only run these operations when you need to. The best practice is to open the connection when your application starts up, and to leave it open until your application restarts or shuts down. This is the approach we’re going to take. SETTING UP THE CONNECTION FILE When we first sorted out the file structure for the application we created three folders inside the app_server folder: models, views, and controllers.
Recommended publications
  • Full-Stack Javascript Development with Mean Pdf Free Download MEAN.JS Tutorial
    full-stack javascript development with mean pdf free download MEAN.JS Tutorial. The term MEAN.js refers to full stack JavaScript framework, used for building dynamic websites and web applications. MEAN is an acronym that stands for M ongoDB, E xpress, N ode.js and A ngularJS, which are the key components of the MEAN stack. Audience. This tutorial is designed for software programmers who want to learn the basics of MEANjs and its programming concepts in simple and easy ways. This tutorial will give you enough understanding on components of MEANjs with suitable examples. Prerequisites. Before proceeding with this tutorial, we are assuming that you are already aware of the basics of HTML, CSS, and JavaScript. Free Download Full Stack JavaScript Development with MEAN – Value $30. Today's free download from Wccftech Deals offers you to get Full Stack JavaScript Development with MEAN e-book for absolutely free. Originally valued at $30, you can now download this ebook for free. This ebook is designed to help intermediate-level web designers and developers with previous experience with HTML, CSS, and JavaScript. Full Stack JavaScript Development with MEAN (free eBook - $30 value) With modern tools, it is possible to create production-grade applications using only JavaScript, HTML, and CSS. The combination of MongoDB, Express, AngularJS, and Node.js, all JavaScript technologies, has become so popular that it’s been dubbed the MEAN stack. This book will explore the MEAN stack in detail. We will begin by covering Node.js, as it will lay the groundwork for all of our server-side work.
    [Show full text]
  • Learning React Functional Web Development with React and Redux
    Learning React Functional Web Development with React and Redux Alex Banks and Eve Porcello Beijing Boston Farnham Sebastopol Tokyo Learning React by Alex Banks and Eve Porcello Copyright © 2017 Alex Banks and Eve Porcello. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com/safari). For more information, contact our corporate/insti‐ tutional sales department: 800-998-9938 or [email protected]. Editor: Allyson MacDonald Indexer: WordCo Indexing Services Production Editor: Melanie Yarbrough Interior Designer: David Futato Copyeditor: Colleen Toporek Cover Designer: Karen Montgomery Proofreader: Rachel Head Illustrator: Rebecca Demarest May 2017: First Edition Revision History for the First Edition 2017-04-26: First Release See http://oreilly.com/catalog/errata.csp?isbn=9781491954621 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Learning React, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. While the publisher and the authors have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
    [Show full text]
  • Typescript Language Specification
    TypeScript Language Specification Version 1.8 January, 2016 Microsoft is making this Specification available under the Open Web Foundation Final Specification Agreement Version 1.0 ("OWF 1.0") as of October 1, 2012. The OWF 1.0 is available at http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0. TypeScript is a trademark of Microsoft Corporation. Table of Contents 1 Introduction ................................................................................................................................................................................... 1 1.1 Ambient Declarations ..................................................................................................................................................... 3 1.2 Function Types .................................................................................................................................................................. 3 1.3 Object Types ...................................................................................................................................................................... 4 1.4 Structural Subtyping ....................................................................................................................................................... 6 1.5 Contextual Typing ............................................................................................................................................................ 7 1.6 Classes .................................................................................................................................................................................
    [Show full text]
  • Typescript-Handbook.Pdf
    This copy of the TypeScript handbook was created on Monday, September 27, 2021 against commit 519269 with TypeScript 4.4. Table of Contents The TypeScript Handbook Your first step to learn TypeScript The Basics Step one in learning TypeScript: The basic types. Everyday Types The language primitives. Understand how TypeScript uses JavaScript knowledge Narrowing to reduce the amount of type syntax in your projects. More on Functions Learn about how Functions work in TypeScript. How TypeScript describes the shapes of JavaScript Object Types objects. An overview of the ways in which you can create more Creating Types from Types types from existing types. Generics Types which take parameters Keyof Type Operator Using the keyof operator in type contexts. Typeof Type Operator Using the typeof operator in type contexts. Indexed Access Types Using Type['a'] syntax to access a subset of a type. Create types which act like if statements in the type Conditional Types system. Mapped Types Generating types by re-using an existing type. Generating mapping types which change properties via Template Literal Types template literal strings. Classes How classes work in TypeScript How JavaScript handles communicating across file Modules boundaries. The TypeScript Handbook About this Handbook Over 20 years after its introduction to the programming community, JavaScript is now one of the most widespread cross-platform languages ever created. Starting as a small scripting language for adding trivial interactivity to webpages, JavaScript has grown to be a language of choice for both frontend and backend applications of every size. While the size, scope, and complexity of programs written in JavaScript has grown exponentially, the ability of the JavaScript language to express the relationships between different units of code has not.
    [Show full text]
  • The Complete Beginner's Guide to React
    The Complete Beginner’s Guide to React By Kristen Dyrr Software Engineer and Web Developer This book is brought to you by Zenva - Enroll in our Full-Stack Web Development Mini-Degree to go from zero to Full-Stack engineer. © Zenva Pty Ltd 2018. All rights reserved Table of Contents Chapter 1: Beginner’s Guide to React.js, With Examples Download the source code Learn React online Tutorial requirements Downloading React and getting started Why React is better with JSX Understanding React components React component states How to use props Organizing your interface Chapter 2: Form Validation Tutorial with React.JS Download the source code Tutorial requirements Getting started with the tutorial Setting up for form submission Creating abstract form elements Creating input fields Chapter 3: How to Submit Forms and Save Data with React.js and Node.js Download the tutorial files Tutorial requirements Making revisions to a React user interface Displaying new data from everyone Submitting form data Emptying fields on form submission Saving data to the server Chapter 4 Creating a Crossword Puzzle game with React.JS Download the source code Tutorial requirements Intro to JSFiddle Downloading React Defining Components Rendering Components Populating Props Populating Properties in the Game Composing Components Events Forms This book is brought to you by Zenva - Enroll in our Full-Stack Web Development Mini-Degree to go from zero to Full-Stack engineer. © Zenva Pty Ltd 2018. All rights reserved Chapter 1: Beginner’s Guide to React.js, With Examples React.js is a JavaScript library that was created by Facebook. It is often thought of as the “view” in a model-view-controller (MVC) user interface.
    [Show full text]
  • Static Typescript
    1 Static TypeScript 56 2 57 3 An Implementation of a Static Compiler for the TypeScript Language 58 4 59 5 60 6 Thomas Ball Peli de Halleux Michał Moskal 61 7 Microsoft Research Microsoft Research Microsoft Research 62 8 Redmond, WA, United States Redmond, WA, United States Redmond, WA, United States 63 9 [email protected] [email protected] [email protected] 64 10 Abstract 65 11 66 12 While the programming of microcontroller-based embed- 67 13 dable devices typically is the realm of the C language, such 68 14 devices are now finding their way into the classroom forCS 69 15 education, even at the level of middle school. As a result, the 70 16 use of scripting languages (such as JavaScript and Python) 71 17 for microcontrollers is on the rise. 72 18 We present Static TypeScript (STS), a subset of TypeScript (a) (b) 73 19 (itself, a gradually typed superset of JavaScript), and its com- 74 20 piler/linker toolchain, which is implemented fully in Type- Figure 1. Two Cortex-M0 microcontroller-based educational 75 21 Script and runs in the web browser. STS is designed to be use- devices: (a) the BBC micro:bit has a Nordic nRF51822 MCU 76 22 ful in practice (especially in education), while being amenable with 16 kB RAM and 256 kB flash; (b) Adafruit’s Circuit Play- 77 23 to static compilation targeting small devices. A user’s STS ground Express (https://adafruit.com/products/3333) has an 78 24 program is compiled to machine code in the browser and Atmel SAMD21 MCU with 32 kB RAM and 256 kB flash.
    [Show full text]
  • Choosing the Right Javascript Framework for Your Next Web
    Choosing the Right JavaScript Framework for Your Next Web Application by Brandon Satrom © 2017 Progress. All Rights Reserved. All Rights © 2017 Progress. 2018 WHITEPAPER Table of Contents The Current State of Web Frameworks / 3 Tooling Considerations / 22 Evaluation Criteria / 5 UI & Component Libraries / 22 Ecosystem Considerations / 7 IDE & Tooling Support / 23 History & Longevity / 7 Companion & CLI Tools / 24 Popularity / 9 Enterprise Considerations / 26 Corporate Support / 11 Licensing / 26 Community & Ecosystem / 12 Support & Upgrade Paths / 27 Framework Considerations / 13 Security / 29 Getting Started Experience / 13 Talent Pool & Resources / 30 Skill Requirements / 15 Making a Choice / 33 Completeness of Offering / 17 Size & Performance / 18 Beyond the Browser Options / 21 © 2018 Progress. All Rights Reserved. All Rights © 2018 Progress. Progress / Kendo UI 2 The state of web application development has changed drastically in the past ten years. These changes have been spurred on by greater bandwidth for many, more powerful and feature-rich browsers. The result is a thriving web ecosystem with sites, apps and experiences that would have been hard to imagine a decade ago. And yet, for many developers, this ecosystem often feels like a bazaar, stuffed with libraries and frameworks that do anything and everything one could imagine. For every need there are a dozen options to choose from, and with new stalls (libraries) opening every day, it’s no wonder many of us pine for the days when starting a new project was as simple as dropping jQuery in a script tag. The Current State of Web Frameworks There’s no doubt that the web has grown in complexity, and our development tooling options have grown along with it.
    [Show full text]
  • Modern Web Application Development Using MEAN Stack 1
    A Three Day National Level Workshop on A THREE DAY NATIONAL Advisory Committee LEVEL WORKSHOP ON Modern Web Application Development using MEAN Stack 1. Prof. D.Subba Rao, Rector, JNTUA. Modern Web Application 2. Prof . M.Vijay Kumar, Registrar, JNTUA. Development using MEAN Stack th th th 26 , 27 and 28 SEPTEMBER 2019 3. Prof. A.Ananda Rao, Director R&D, JNTUA 26th, 27th and 28th SEPTEMBER 2019 Under 4. Prof. B.Eswar Reddy, Director SDC, JNTUA Under TEQIP – III 5. Prof. C.Shobabindu, Director SDC & IC, JNTUA TEQIP – III Registration Form 6. Prof. S.Vasundra, NSS Coordinator, JNTUA 7. Dr. R.Rajasekhar, Associate Professor of CSE Name: 8. Dr. K.Madhavi, Associate Professor of CSE Branch: 9. Dr. A.P.Siva Kumar, TEQIP-III Coordinator 10. Dr. K.F.Bharati, Assistant Professor of CSE Qualification: Organization: Address for Communication: Prof . P Chenna Reddy , Organized by Address: Professor of CSE Department of Computer Science &Engineering JNTUA College of Engineering Dr. B. Lalitha, (Autonomous) :: Ananthapuramu Mobile No: Assistant Professor of CSE Andhra Pradesh, India www.jntuacea.ac.in Email: Co-Ordinators, Modern Web Application Development using MEAN Stack Workshop Chief Patron Place: Department of CSE Prof. S.Srinivas Kumar Date: Signature of the Applicant JNTUA College of Engineering, Hon’ble Vice Chancellor Ananthapuramu- 515002, JNT University Ananthapuramu. Forwarded through Head of the Dept. / Institute Andhra Pradesh, Ph No: 9885336491 Patron Email: meanworkshop.jntuacea @gmail.com Prof. K.Govinda Rajulu Principal, JNTUACEA Co-Coordinator Mr. K. Anil Kumar, Co-Patron Assistant Professor (Adhoc), Prof. M.L.S. Devakumar Phone No: 7780553796 Vice Principal & TEQIP Nodal Officer Student Organizers: Convener Prof.
    [Show full text]
  • Mean Stack Web Development
    International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056 Volume: 07 Issue: 05 | May 2020 www.irjet.net p-ISSN: 2395-0072 Mean Stack Web Development Logesh M1, Karthika K2 1Student, Electronics and Communication Engineering, Kumaraguru College of Technology, Coimbatore, India. 2Assistant Professor, Electronics and Communication Engineering, Kumaraguru College of Technology, Coimbatore, India. ----------------------------------------------------------------------***--------------------------------------------------------------------- Abstract — With the recent advancement of digital source stack of JavaScript tools to create interactive technology, developers and technologists around the globe websites and web applications. Since all MEAN stack have never had a more exciting time to set up new web components support programs written in JavaScript, applications. There are plenty of new languages, web MEAN applications can be written in one language for both frameworks and resources to choose from for the creation of server- and client-side execution environments. Web applications. E-commerce is one of the newest innovations designed to open up great opportunities for MEAN is extremely simplistic for rear end and business people. One of e-commerce's most popular areas front end in various systems, but for server and client side are e-Business areas. MEAN stack technology was the tool execution, the separate languages for front and back end used to create an e-commerce website. It is one of the strong are written in a single language. It is a free and open- full stack technologies used to develop the most trafficking source stack of JavaScript software that is very important sites. This paper looks at the four MEAN stack components for the creation of dynamic Mean stack frameworks and (Mongo Db, Express Js, Angular & Node Js) and how they go websites [2].Over recent years, due to the advancement in well together, their virtues as a full stack in web design.
    [Show full text]
  • Certificate Course in “MEAN Stack Web Development”
    Certificate Course in “MEAN Stack Web Development” MEAN Stack Overview: MEAN is an acronym for MongoDB, ExpressJS, Angular and Node.js. MEAN Stack web development is a structured learning path recommended by leading industry experts and ensures your mastery of full MEAN stack development. MongoDB is a schemaless NoSQL database system. MongoDB saves data in binary JSON format which makes it easier to pass data between client and server. ExpressJS is a lightweight framework used to build web applications in Node. It provides a number of robust features for building single and multi page web application. ExpressJS is inspired by the popular Ruby framework, Sinatra. Angular is a TypeScript based open-source front-end web application platform led by the Angular Team at Google. It gives an extraordinarily expressive, readable and fast way to develop rich front ends for websites. Node.js is a server side JavaScript execution environment. It is a platform built on Google Chrome’s V8 JavaScript runtime. It helps in building highly scalable and concurrent applications rapidly. 1 Course Objective: The overall aim of the course is to enable participants to confidently build different types of application using the MEAN stack. The course is divided into four modules, MongoDB, ExpressJS, Angular, and Node.js. Each module focuses on a different goal. The four modules work together building a full application, with an overall outcome of showing how to architect and build complete MEAN applications. Course Details: Title Certificate Course in MEAN Stack Web Development No. of Credits 5 (Total No. of Clock Hours = 75) Duration 13 Weeks Actual Contact Hours 60 Classroom Training (with hands-on) Project Based Learning Hours 15 Fee Structure 15000.00 / Participant Open for all Students / Individuals/ Professionals with Eligibility basic knowledge of HTML5, CSS3 and JavaScript Intake 30 Participants Outcome: By the end of the course, participants will be able: To set up a web-server using Node.js and ExpressJS, to listen for request and return response.
    [Show full text]
  • Javascript for Science
    JavaScript for Science [email protected] Inverted CERN School of Computing (16-18 March, 2020) Content • Popularity of JavaScript • Evolution of Node.js • Rich ecosystem of JavaScript libraries • JavaScript libraries for scientific tasks • Performance of JavaScript * Most of the framed images are linked to their relevant content 2/37 JavaScript, the native language of the Web JavaScript (JS) is a high-level, object oriented, interpreted programming language. • The JS was created by Brendan Eich in 1995 at Netscape as a scripting tool to manipulate web pages inside Netscape Navigator browser. • Initially JS had another name: “LiveScript”. But Java was very popular at that time, so it was decided that positioning a new language as a “younger brother” of Java would help to make it noticeable. 3/37 Popular programming languages by StackOverflow StackOverflow developers survey (2013-2019) 4/37 Top programing languages by Github Every year, GitHub releases the Octoverse report, ranking the top technologies favored by its community of millions of software developers. 5/37 Top 5 Programming languages by SlashData Developer analyst and research company SlashData, which helps top 100 technology firms understand their developer audiences, surveyed 17000+ developers from 155 countries and revealed the following report: 6/37 Why JS became so popular? • JS is the language of the Web. • The introduction of Node.js allowed JS to go beyond the browser. • JS can serve as a universal language to build cross-platform isomorphic software systems, which makes the language very cost-efficient. Web Thanks to MongoDB! Mobile Server Database Desktop An isomorphic software system 7/37 What is Node.js • An open-source, cross-platform, JS runtime environment written in C++ • Uses V8 JS engine to execute JS code outside of a browser, i.e.
    [Show full text]
  • Introducing the MEAN Stack
    Introducing the MEAN stack CS252 The MEAN stack ● MongoDB: mongodb.org ● Express: expressjs.com ● AngularJS: angularjs.org ● Node: nodejs.org ● All free and open-source ● All based on JavaScript The LAMP stack OS Linux Web Server Apache Database MySQL Server-side language PHP The Microsoft stack OS Microsoft Web Server IIS Database SQL Server Server-side language C#/.NET Many moving parts ● HTML ● CSS ● JavaScript ● PHP ● MySQL ● JSON ● How do we get everything to work together? Typical workflow ● Code mainly runs on the server ● Exception: JavaScript ● Data is mainly stored on server ● Data processing can happen either on server or at client ● Server side processing = greater security ● Client side processing = greater computing efficiency Typical workflow ● Code mainly runs on the server ● Exception: JavaScript ● Data is mainly stored on server ● Data processing can happen either on server or at client ● Server side processing = greater security ● Client side processing = greater computing efficiency Client side code Server side code Database The MVC abstraction Models Views The data interface The user interface Controllers The interaction middleware MVC – general example The MEAN stack compared LAMP Microsoft MEAN OS Linux Windows Typically Linux Web Server Apache IIS Node Database MySQL SQL Server MongoDB Server-side scripting PHP C#/.NET JavaScript Server-side MVC Express Client-side MVC Angular MEAN stack is JavaScript all the way through Very fast and responsive; naturally async Mongo ● We saw this last week ● Schemaless document storage in JSON format ● Supports indexes ● No joins ● Blazing fast How to use? ● db.users.insert({name: ‘some_name’}) ● db.users.find({name: ‘some_name’}) ● db.users.find({age: {$gt: 18}}, {name: 1, address: 0}).limit(5) ● db.users.distinct(“name”) ● Very powerful concept: Aggregation – https://docs.mongodb.com/manual/aggregation/ Aggregation ● db.collection.aggregate([ ..
    [Show full text]