Setting up an Angular 4 MEAN Stack (Tutorial)

Similar documents
By the end of this Angular 6 tutorial, you'll learn by building a real world example application:

Integrating Angular with ASP.NET Core RESTful Services. Dan Wahlin

One Framework. Angular

Before proceeding with this tutorial, you should have a basic understanding of HTML, CSS, JavaScript, TypeScript, and Document Object Model (DOM).

IN4MATX 133: User Interface Software

Advantages: simple, quick to get started, perfect for simple forms, don t need to know how form model objects work

Mobile App Development

Cross-Platform Mobile-Entwicklung mit dem Ionic Framework

Node.js. Node.js Overview. CS144: Web Applications

Upgrading to Ionic 3 APPENDIX D. Angular 4

Lab 1 - Introduction to Angular

About me. Google Developer Expert Telerik Developer Expert Digital

Decoupled Drupal with Angular

Angular. конфигурируем до неузнаваемости

Learn to Build Awesome Apps with Angular 2

Introduction to. Angular. Prof. Dr.-Ing. Thomas Wiedemann.

About me. Routing into the Sunset with Angular. Manfred Steyer SOFTWAREarchitekt.at Trainer & Consultant Focus: Angular Google Developer Expert (GDE)

Hands on Angular Framework

ANGULAR2 OVERVIEW. The Big Picture. Getting Started. Modules and Components. Declarative Template Syntax. Forms

SAMPLE CHAPTER SECOND EDITION. Alex Young Bradley Meck Mike Cantelon. Tim Oxley Marc Harter T.J. Holowaychuk Nathan Rajlich MANNING WITH

#06 RPC & REST CLIENT/SERVER COMPUTING AND WEB TECHNOLOGIES

Angular from the Beginning

Markeplace web application with Foglab (Foglab with Marketplace)

Chapter 1 - Model Driven Forms

Updating web content in real time using Node.js

What is Node.js? Tim Davis Director, The Turtle Partnership Ltd

Learn to Build Awesome Apps with Angular 2

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. GraphQL

Running and Debugging Custom Components Locally

Sample Copy. Not For Distribution.

COMP 2406: Fundamentals of Web Applications. Winter 2014 Mid-Term Exam Solutions

TypeScript. TypeScript. RxJS

Advanced Express Web Application Development

We are assuming you have node installed!

Angular 2: What s new? Jonas Bandi, IvoryCode GmbH

Chapter 1 - Development Setup of Angular

Extending VMware vcloud Director User Interface Using Portal Extensibility Ticketing Example

CS193X: Web Programming Fundamentals

Advanced Angular & Angular 6 Preview. Bibhas Bhattacharya

Front End. Presentation Layer. UI (User Interface) User <==> Data access layer

AngulAr 4 Pocket Primer

IBM Natural Language Understanding Node.js

Frontend UI Training. Whats App :

The Pizza Shop. Overview. Initial Setup

Angular 2 Programming

Frontend Web Development with Angular. CC BY-NC-ND Carrot & Company GmbH

LFE Medieninformatik WS 2016/2017

End-to-End Test and Build

Before I forget... I'm Ari Lerner

From the Beginning: Your First Node.js Web Service

Comprehensive AngularJS Programming (5 Days)

Chapter 1 - Consuming REST Web Services in Angular

Full Stack boot camp

welcome to BOILERCAMP HOW TO WEB DEV

Persistence. SWE 432, Fall 2017 Design and Implementation of Software for the Web

Angular 4 Training Course Content

Oracle Bots Nodes.js SDK: Controlling Smart Homes Using IFTTT Applets with Oracle Digital Assistant

Arjen de Blok. Senior Technical Consultant bij ICT Groep ( sinds 1995 Programmeren sinds 1990 Technologiën. Links

3 Days Training Program

Index. Backbone.js app, 274 Behavior-driven development (BDD) language, 252 bodyparser() method, 257

Express.JS. Prof. Cesare Pautasso Modularity

The course is supplemented by numerous hands-on labs that help attendees reinforce their theoretical knowledge of the learned material.

DNCMagazine. ANGULAR. Cheat Sheet

INTRODUCTION TO IONIC 2

CSc 337 LECTURE 16: WRITING YOUR OWN WEB SERVICE

NODE.JS SERVER SIDE JAVASCRIPT. Introduc)on Node.js

Progressive web app. Juraj Kubala

Extra Notes - Data Stores & APIs - using MongoDB and native driver

Getting Started with IBM Bluemix Hands-On Workshop. Module 6a: Services

Microservices with Node.js

Development of a New Web Portal for the Database on Demand Service

Index. Bare-bones connect application, 125 Binary JSON (BSON), 171. Callback functions asynchronous code ifelse, 199 loops,

Advance Mobile& Web Application development using Angular and Native Script

AngularJS Intro Homework

Backend Development. SWE 432, Fall Web Application Development

Catbook Workshop: Intro to NodeJS. Monde Duinkharjav

Lab 6: Testing. Software Studio DataLab, CS, NTHU

Tarek Elachkar, VP Customer Solutions - Jahia A real world story of Angular and Apache Unomi integration.

a Very Short Introduction to AngularJS

Cookies, sessions and authentication

RadiantQ jquery Gantt Package. RadiantQ,

MAKE NODEJS APIs GREAT WITH TYPESCRIPT

Client Side JavaScript and AJAX

MEAN Stack. 1. Introduction. 2. Foundation a. The Node.js framework b. Installing Node.js c. Using Node.js to execute scripts

MongoDB. Robert M. Vunabandi

ShareSci: A Research Paper Networking Site

Lightweight Platform for Internet of Things with support for CoAP Block-wise Transfer

mongodb-tornado-angular Documentation

COMP 2406: Fundamentals of Web Applications Winter 2014 Final Exam Solutions Instructor: Anil Somayaji April 24, 2014

Introduction to Express.js. CSC309 Feb. 6, 2015 Surya Nallu

Angular2. Bernhard Niedermayer. Software Development playing around with Angular2 since alpha.

ANGULAR 2.X,4.X + TYPESRCIPT by Sindhu

About Me. Name: Jonathan Brown. Job: Full Stack Web Developer. Experience: Almost 3 years of experience in WordPress development

Production Registration System 2.0

Lets take a closer look at Ajax & node.js. Claudia Hauff TI1506: Web and Database Technology

Demystifying Angular 2. SPAs for the Web of Tomorrow

MongoDB Web Architecture

Ajax- XMLHttpResponse. Returns a value such as ArrayBuffer, Blob, Document, JavaScript object, or a DOMString, based on the value of

MANTRA REGISTERED DEVICE SERVICE WINDOWS MANTRA SOFTECH INDIA PVT LTD

IERG Tutuorial 5. Benedict Mak

Transcription:

Setting up an Angular 4 MEAN Stack (Tutorial) MEAN4 Stack, MongoDB, Express.js, Angular4, Node.js6.11.4 Installed https://coursetro.com/posts/code/84/setting-up-an-angular-4-mean-stack-(tutorial) Node.js Angular4 Express.js MongoDB Setup setup MongoDB locally api.js Once start MongoDB (mongod.exe) open another command prompt and connect to it through the shell by running mongo.exe Inside the shell create DB insert names into DB http://localhost:3000/ verified DB by accessing it by directly visiting the API endpoint URL Setup Angular to access data data.service.ts app.module.ts app.component.ts app.component.html ng build Angular 1

Testing run node server 2

localhost:3000 Supporting Files changed, added 3 Karma.conf.js // Karma configuration file, see link for more information // https://karma-runner.github.io/1.0/config/configuration-file.html module.exports = function (config) { config.set({ basepath: '', frameworks: ['jasmine', '@angular/cli'], plugins: [ require('karma-jasmine'), require('karma-chrome-launcher'), require('karma-jasmine-html-reporter'), require('karma-coverage-istanbul-reporter'), require('@angular/cli/plugins/karma') ], client:{ clearcontext: false // leave Jasmine Spec Runner output visible in browser, coverageistanbulreporter: {

reports: [ 'html', 'lcovonly' ], fixwebpacksourcepaths: true, angularcli: { environment: 'dev', reporters: ['progress', 'kjhtml'] port: 9876, colors: true, loglevel: config.log_info, autowatch: true, browsers: ['Chrome'], singlerun: false ; server.js const express = require('express'); const bodyparser = require('body-parser'); const path = require('path'); const http = require('http'); const app = express(); // API file for interacting with MongoDB const api = require('./server/routes/api'); // Parsers app.use(bodyparser.json()); app.use(bodyparser.urlencoded({ extended: false)); // Angular DIST output folder app.use(express.static(path.join( dirname, 'dist'))); // API location app.use('/api', api); // Send all other requests to the Angular app app.get('*', (req, res) => { res.sendfile(path.join( dirname, 'dist/index.html')); //Set Port const port = process.env.port '3000'; app.set('port', port); const server = http.createserver(app); server.listen(port, () => console.log(`running on localhost:${port`)); 4

mongod.cfg systemlog: destination: file path: c:\data\log\mongod.log storage: dbpath: c:\data\db api.js const express = require('express'); const router = express.router(); const MongoClient = require('mongodb').mongoclient; const ObjectID = require('mongodb').objectid; // Connect const connection = (closure) => { return MongoClient.connect('mongodb://localhost:27017/mean', (err, db) => { if (err) return console.log(err); ; closure(db); // Error handling const senderror = (err, res) => { response.status = 501; response.message = typeof err == 'object'? err.message : err; res.status(501).json(response); ; // Response handling let response = { status: 200, data: [], message: null ; // Get users router.get('/users', (req, res) => { connection((db) => { db.collection('users').find().toarray().then((users) => { response.data = users; res.json(response); ) 5

.catch((err) => { senderror(err, res); module.exports = router;: data.service.ts import { Injectable from '@angular/core'; import { Http, Headers, RequestOptions from '@angular/http'; import 'rxjs/add/operator/map'; @Injectable() export class DataService { result:any; constructor(private _http: Http) { getusers() { return this._http.get("/api/users").map(result => this.result = result.json().data); 6 app.module.ts import { BrowserModule from '@angular/platform-browser'; import { NgModule from '@angular/core'; import { AppComponent from './app.component'; // Import the Http Module and our Data Service import { HttpModule from '@angular/http'; import { DataService from './data.service'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, HttpModule // <-Add HttpModule ], providers: [DataService], // <-Add DataService bootstrap: [AppComponent]

) export class AppModule { app.component.ts import { Component from '@angular/core'; // Import the DataService import { DataService from './data.service'; @Component({ selector: 'app-root', templateurl: './app.component.html', styleurls: ['./app.component.css'] ) export class AppComponent { // Define a users property to hold our user data users: Array<any>; // Create an instance of the DataService through dependency injection constructor(private _dataservice: DataService) { // Access the Data Service's getusers() method we defined this._dataservice.getusers().subscribe(res => this.users = res); app.component.html <div style="text-align:center"> <h1> MEAN Stack, MongoDB, Express.js, Angular4, Node.js6.11.4 <br> Mongo.exe connects thru this shell to Mongod.exe (MongoDB) </h1> </div> <ul> <li *ngfor="let user of users">{{ user.name </li> </ul> 7