[ Angular2 Updated to 4.2.0 ]
Angular2 MEAN - QuickStart application with ExpressJS, MongoDB, Gulp and Typescript (Repository Pattern)
##Introduction
Basic Angular seed application created with Quick start application (Tour of Heroes) given on angular website. It uses ExpressJS along with Mongo DB support (Mongoose) via a wrapper of Repository Pattern as Business layer. It also uses Gulp for running task and TsLint.The seed application is built over node and uses latest node packages.
https://angular2-express-mongoose.herokuapp.com/
Prerequisites
- Latest version of Node to be installed.
- Install MongoDB and make sure it is running on default port 27017 (if not then please configure constants.ts and change the connection for mongoDB).
Global packages
npm install ts-node -g
npm install typescript-node -g
Steps to Run
npm install <= install all the npm Dependencies
npm run build <= build and compile the dest folder
npm run deploy <= start the Nodemon and watch for changes.
Directory Structure
angular2-MEAN
βββ node_modules
βββ client
β βββ app
β β βββ Components
β β β βββ dashboard
β β β β βββ dashboard.component.css
β β β β βββ dashboard.component.html
β β β β βββ dashboard.component.ts
β β β βββ heroDetail
β β β β βββ hero-detail.component.css
β β β β βββ hero-detail.component.html
β β β β βββ hero-detail.component.ts
β β β βββ heroes
β β β β βββ heroes.component.css
β β β β βββ heroes.component.html
β β β β βββ heroes.component.ts
β β βββ models
β β β βββ hero.ts
β β βββ services
β β β βββ hero.service.ts <= Hero Service for fetching api
β β βββ app.component.css
β β βββ app.component.ts
β β βββ app.html
β β βββ app.module.ts
β β βββ app.routing.ts
β β βββ main.ts
β βββ typings
β βββ index.html
β β βββ systemjs.config.js
β βββ tsconfig.json
β βββ typings.json
βββ server
β βββ src
β β βββ app
β β β βββ business <= business logic for application
β β β β βββ common
β β β β β βββ Read.ts <= common Read method
β β β β β βββ Write.ts <= common Write method
β β β β βββ interfaces
β β β β β βββ HeroBusiness.ts
β β β β βββ BaseBusiness.ts
β β β β βββ HeroBusiness.ts
β β β βββ dataAccess
β β β β βββ schemas
β β β β β βββ HeroSchema.ts <= Hero Schema for MongoDB
β β β β βββ DataAccess.ts <= Connection with MongoDB
β β β βββ model
β β β β βββ interfaces
β β β β β βββ HeroModel.ts
β β β β βββ HeroModel.ts
β β β βββ repository
β β β β βββ interfaces
β β β β β βββ Read.ts
β β β β β βββ Write.ts
β β β β βββ BaseRepository.ts
β β β β βββ HeroRepository.ts
β β βββ config
β β β βββ constants
β β β β βββ constants.ts <= Constants - mongodb connection string.
β β β βββ routes
β β β β βββ HeroRoutes.ts <= Hero API Routes like get,post,put,delete
β β β β βββ Routes.ts <= fetching all appliction routes here
β β βββ controller
β β β βββ interfaces
β β β β βββ ReadController.ts
β β β β βββ WriteController.ts
β β β βββ BaseController.ts <= Base Repository controller
β β β βββ HeroController.ts
β β βββ server.ts
β βββ typings
β βββ tsconfig.json
β βββ tsconfig.json
βββ gulpfile.ts <= gulp tasks : clean, build, compile, run.
βββ LICENSE
βββ package.json
βββ README.md
βββ tsconfig.json
βββ tslint.json
Features (Angular2, Express, Gulp, MongoDB, Node)
- Angular 2 Quick Start application (Tours of Hero) from https://angular.io/docs/ts/latest/quickstart.html
- Added support for Gulp so that js files are moved out of the app folder.
- It will create a dist folder where it will place all the js files.
- Gulp will monitor for the changes via help of watcher.
- Created folder structure for easy access of components, services and models.
- Applied tslint for avoiding any typos.
- Implemented best practices recomended on the Angular 2 website.
- Implemented Express Server to Host API's
- Added MongoDB support to communicate our Heroes data to Database
- Implemented Repository Pattern to communicate with Mongoose.
Api Document (from MongoDB)
1. getAll http://localhost:3000/api/heroes <= get all heroes
1. getById http://localhost:3000/api/heroes/:id <= get hero by Id
2. post http://localhost:3000/api/heroes <= create hero
2. put http://localhost:3000/api/heroes/:id <= update hero
2. delete http://localhost:3000/api/heroes/:id <= delete hero
Dependencies
- Angular 2
- TypeScript
- Gulp
- ExpressJS
- NodeJS
- Nodemon
- TsLint
- MongoDB
License
MIT