A MEAN stack development kit featuring Angular 2 (Router, Http, Forms, Services, Tests, E2E, Coverage, Dev/Prod), Express, MongoDB, Mongoose, Node, PassportJS, Socket.io, Karma, Protractor, Jasmine, Istanbul, SASS Support, TypeScript, TSLint, NG2Lint, Hot Module Replacement, Docco, Gulp, and Webpack by Da5id
JavaScript TypeScript HTML CSS
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Dependency Status Build Status GitHub release Issue Stats Issue Stats Stack Share Angular 2 Style Guide

MEAN with NG2 and Webpack

MEAN Stack Development Starter Join Slack

This project is no longer maintained. Please visit vulgar to follow the new version, and check out our new command line tool for generating and managing cutting-edge MEAN stack apps at vulgar-cli

A MEAN stack development kit featuring Angular 2 (Router, Forms, Http, Services, Tests, E2E), Express, MongoDB (complete with Mongoose), Node, PassportJS, Socket.IO, Karma, Protractor, Jasmine, Istanbul, TypeScript, Typings, Sass, Docco, TsLint, Ng2Lint, Hot Module Replacement, and Webpack, as well as ES6/ES7 support for the back-end by datatype_void.

Walk through a complete tutorial that shows you how to build a simple todo app using this framework, check out Building A Single Page Todo App with MEAN--Including Angular 2

If you're looking to learn about Webpack and ES6 Build Tools check out ES6-build-tools

If you're looking to learn TypeScript see TypeStrong/learn-typescript

If you're looking to learn how to move your Angular 1.x directives over to Angular 2 see Migrating Directives to Angular 2

And always keep the Angular 2 docs at hand, because the times are always changing

This seed repo serves as an MEAN starter for anyone looking to get a MEAN fullstack app up and running with Angular 2, TypeScript(on the front-end), and ES6/ES7 (on the back-end) fast. Using Webpack for building our files and assisting with boilerplate. We're also using Protractor for our end-to-end story and Karma for our unit tests.

  • Best practices in file and application organization for Angular 2.
  • Ready to go build system using Webpack for working with TypeScript.
  • Hot module reloading for the front-end à la Webpack.
  • Angular 2 examples that are ready to go when experimenting with Angular 2.
  • A great MEAN seed repo for anyone who wants to start their project.
  • Testing Angular 2 code with Jasmine and Karma.
  • Coverage with Istanbul and Karma
  • End-to-end Angular 2 code using Protractor.
  • Type manager with Typings
  • Sass preprocessor linting and compiling
  • Automatic documentation for all project related Sass, TypeScript, and JavaScript files with Docco; front-end and back-end

The rest of the stack features:

Quick start

Clone/Download the repo then edit app.ts inside /src/app/app.ts

# clone our repo
# --depth 1 removes all but one .git commit history
git clone --depth 1 https://github.com/datatypevoid/ng2-mean-webpack.git

# change directory to our repo
cd ng2-mean-webpack

# add required global libraries
 npm install -g typings webpack-dev-server concurrently

# install the repo with npm
npm install

# create configuration json file for env vars
# save in `config/` as `config.json`
  "ENV" : "development",
  # Cannot be 8080 as this conflicts with our Webpack dev server
  "PORT" : 3000,
  "MONGO_URI" : {
    "DEVELOPMENT" : "mongodb://[username:password]@host[:port]",
    "PRODUCTION" : "mongodb://[username:password]@host[:port]",
    "TEST" : "mongodb://[username:password]@host[:port]"
  # Generate your own 256-bit WEP key here:
  # http://randomkeygen.com/
  # Note that you don't need to use specifically
  # this, but it will certainly suffice
  "SESSION_SECRET" : "355FC4FE9348639B4E4FED1B8E93C"

# build code
npm run build

# start up the stack

# this command runs two commands in parallel via `concurrently`:
# `npm run server` starts up `webpack-dev-server` allowing for
# hot module reloading
# `npm` run watch` uses `webpack` to watch the necessary files
# and build on file change
npm start

# in a separate terminal:
# start `Express` server
gulp serve

go to or http://localhost:8080 in your browser

Table of Contents

File Structure

We use the component approach in our starter. This is the new standard for developing Angular apps and a great way to ensure maintainable code by encapsulation of our behavior logic. A component is basically a self contained app usually in a single file or a folder with each concern as a file: style, template, specs, e2e, and component class. Here's how it looks:

 ├──app/                            * our source files for back-end routing and MongoDB object modelling
 │   ├──models/                     * model definitions for Mongoose
 │   │   ├──user.model.js           * a user model for use with PassportJS
 │   ├──routes/                     * store all modular REST API routes for Express here
 │   │   └──authentication          * an Express route for use with PassportJS
 │   │        .router.js
 │   └──routes.js                   * gather all of your Express routes and middleware here
 ├──config/                         * configuration files for environment variables, Mongoose, and PassportJS
 │   ├──config.json/                * allows definition of environment variables
 │   ├──env.conf.js/                * contains utility functions for setting up environment vars
 │   ├──mongoose.conf.js/           * configuration file for Mongoose
 │   └──passport.conf.js/           * configuration file for PassportJS
 ├──sockets/                        * directory for socket.io functionality
 │   └──base.js/                    * a basic socket.io server function
 ├──src/                            * our source files that will be compiled to javascript
 │   ├──main.ts                     * our entry file for our browser environment
 │   │
 │   ├──index.html                  * Index.html: where we generate our index page
 │   │
 │   ├──polyfills.ts                * our polyfills file
 │   │
 │   ├──app/                        * WebApp: folder
 │   │   ├──todo/                   * an example component directory
 │   │   │   ├──todo.component.ts   * a simple Angular 2 component
 │   │   │   ├──todo.e2e.ts         *  simple test of components in todo.component.ts
 │   │   │   ├──todo.spec.ts        * a simple end-to-end test for /todo
 │   │   │   ├──todo.html           * template for our component
 │   │   │   └──todo.service.ts     * Angular 2 service linking to our API
 │   │   ├──app.spec.ts             * a simple test of components in app.ts
 │   │   ├──app.e2e.ts              * a simple end-to-end test for /
 │   │   └──app.ts                  * App.ts: a simple version of our App component components
 │   │
 │   ├──assets/                     * static assets are served here
 │   │   ├──icon/                   * our list of icons from www.favicon-generator.org
 │   │   ├──service-worker.js       * ignore this. Web App service worker that's not complete yet
 │   │   ├──robots.txt              * for search engines to crawl your website
 │   │   └──human.txt               * for humans to know who the developers are
 │   │
 │   └──sass/                       * folder for Sass stylesheets
 │       |
 │       ├──base/
 │       │   ├──_animations.scss    * Animation keyframe definitions
 │       │   ├──_reset.scss         * Reset/normalize
 │       │   ├──_typography.scss    * Typography rules
 │       │   ├──_module.scss        * Load all partials from this directory into single partial
 │       │   └── …                  * Etc.
 │       │
 │       ├──components/
 │       │   ├──_buttons.scss       * Buttons
 │       │   ├──_carousel.scss      * Carousel
 │       │   ├──_cover.scss         * Cover
 │       │   ├──_dropdown.scss      * Dropdown
 │       │   ├──_module.scss        * Load all partials from this directory into single partial
 │       │   └── …                  * Etc.
 │       │
 │       ├─ layout/
 │       │   ├──_navigation.scss    * Navigation
 │       │   ├──_grid.scss          * Grid system
 │       │   ├──_header.scss        * Header
 │       │   ├──_footer.scss        * Footer
 │       │   ├──_sidebar.scss       * Sidebar
 │       │   ├──_forms.scss         * Forms
 │       │   ├──_module.scss        * Load all partials from this directory into single partial
 │       │   └── …                  * Etc.
 │       │
 │       ├─ pages/
 │       │   ├──_home.scss          * Home specific styles
 │       │   ├──_contact.scss       * Contact specific styles
 │       │   ├──_module.scss        * Load all partials from this directory into single partial
 │       │   └── …                  * Etc.
 │       │
 │       ├─ themes/
 │       │   ├──_theme.scss         * Default theme
 │       │   ├──_admin.scss         * Admin theme
 │       │   ├──_module.scss        * Load all partials from this directory into single partial
 │       │   └── …                  * Etc.
 │       │
 │       ├─ utils/
 │       │   ├──_variables.scss     * Sass Variables
 │       │   ├──_functions.scss     * Sass Functions
 │       │   ├──_mixins.scss        * Sass Mixins
 │       │   ├──_helpers.scss       * Class & placeholders helpers
 │       │   ├──_module.scss        * Load all partials from this directory into single partial
 │       │   └── …                  * Etc.
 │       ├──vendors/
 │       │   ├──_bootstrap.scss     * Bootstrap
 │       │   ├──_jquery-ui.scss     * jQuery UI
 │       │   ├──_module.scss        * Load all partials from this directory into single partial
 │       │   └── …                  * Etc.
 │       │
 │       │
 │       └──main.scss               * Main sass file to load all partials for this project
 ├──.babelrc                        * configure Babel 6 plugins and ES6/ES7 presets
 ├──server.js                       * ES5 `.js` file importing the server code along with a Babel 6 hook to transpile server ES6/ES7 code on the fly
 ├──server.conf.js                  * configure Express/Socket.io application, connect to database, instantiate Mongoose models, define API and front-end Angular routes, et cetera
 ├──gulpfile.js                     * ES5 `gulpfile` importing the `gulp` workflow code along with a Babel 6 hook to transpile the ES6 code on the fly
 ├──gulpfile.conf.js                * contains all of the workflow management delegated to `gulp`: auto documentation generation; `sass` linting; `nodemon`, et cetera
 ├──spec-bundle.js                  * ignore this magic that sets up our angular 2 testing environment
 ├──karma.config.js                 * karma config for our unit tests
 ├──protractor.config.js            * protractor config for our end-to-end tests
 ├──tsconfig.json                   * config that webpack uses for typescript
 ├──typings.json                    * our typings manager
 ├──package.json                    * what npm uses to manage it's dependencies
 ├──webpack.config.js               * our development webpack config
 ├──webpack.test.config.js          * our testing webpack config
 └──webpack.prod.config.js          * our production webpack config

Getting Started


What you need to run this app:

  • node and npm (brew install node)
  • Ensure you're running the latest versions Node v4.1.x+ and NPM 2.14.x+

Once you have those, you should install these globals with npm install --global:

  • webpack (npm install --global webpack)
  • webpack-dev-server (npm install --global webpack-dev-server)
  • karma (npm install --global karma-cli)
  • protractor (npm install --global protractor)
  • typings (npm install --global typings)
  • typescript (npm install --global typescript)


  • fork this repo
  • clone your fork
  • npm install to install all dependencies
  • typings install to install necessary typings
  • create config.json see below
  • npm run build to build necessary front-end code with Webpack
  • npm start to enable hot module reloading and build on file change
  • In a new terminal, node server to start the server for the first time


The server.conf.js file is expecting certain environment variables to be set within Node. The env.conf.js has functions to check whether the expected environment variables have been setup before proceeding to start up the rest of the server. You can create a file called config.json and store it in the config directory that looks something like this:

  "ENV" : "development",
  "PORT" : 3000,
  "MONGO_URI" : {
    "DEVELOPMENT" : "mongodb://[username:password]@host[:port]",
    "PRODUCTION" : "mongodb://[username:password]@host[:port]",
    "TEST" : "mongodb://[username:password]@host[:port]"
  # Generate your own 256-bit WEP key here:
  # http://randomkeygen.com/
  # Note that you don't need to use specifically
  # this, but it will certainly suffice
  "SESSION_SECRET" : "355FC4FE9348639B4E4FED1B8E93C"

Running the app

After you have installed all dependencies and created your config.json file, you can now run the app. First, you must start up the back-end server in a separate terminal using the gulp serve command. This will fire up our Express app using nodemon, which will watch for file changes and restart our backend when necessary. Next use the npm start command in the original terminal which runs two npm scripts in parallel: npm run server to start webpack-dev-server for building our front-end in the computer's memory, enabling hot module reloadig; npm run watch to watch all of the front-end files and build them upon changes. You can now fire up your favorite web browser and visit the running application at localhost:8080!


# development
# package front-end files with Webpack and hot reload
# upon any changes
npm start
# use `Gulp` in a second terminal to run the Express
# app responsible for our back-end
gulp serve
# optionally use `Gulp` in a third terminal to auto
# generate documentation and lint `Sass`

# production
npm run build:prod
npm run server:prod

Other commands

start Express back-end

gulp serve

build documentation

gulp build:docs

watch and build documentation

gulp watch:docs

watch and lint sass

gulp watch:sass

build files

# development
npm run build:dev
# production
npm run build:prod

watch and build files

npm run watch

run tests

npm run test

watch and run our tests

npm run watch:test

run end-to-end tests

# make sure you have your server running in another terminal
npm run e2e

run webdriver (for end-to-end)

npm run webdriver:update
npm run webdriver:start

run Protractor's elementExplorer (for end-to-end)

npm run webdriver:start
# in another terminal
npm run e2e:live


You can include more examples as components but they must introduce a new concept such as Home component (separate folders), and Todo (services). I'll accept pretty much everything so feel free to open a Pull-Request


To take full advantage of TypeScript with autocomplete you would have to install it globally and use an editor with the correct TypeScript plugins.

Use latest TypeScript compiler

TypeScript 1.7.x includes everything you need. Make sure to upgrade, even if you installed TypeScript previously.

npm install --global typescript

Use a TypeScript-aware editor

We have good experience using these editors:


When you include a module that doesn't include Type Definitions inside of the module you need to include external Type Definitions with Typings

Use latest Typings module

npm install --global typings

Custom Type Definitions

When including 3rd party modules you also need to include the type definition for the module if they don't provide one within the module. You can try to install it with typings

typings install node --save

If you can't find the type definition in the registry we can make an ambient definition in this file for now. For example

declare module "my-module" {
  export function doesSomething(value: string): string;

If you're prototyping and you will fix the types later you can also declare it as type any

declare var assert: any;

If you're importing a module that uses Node.js modules which are CommonJS you need to import as

import * as _ from 'lodash';

You can include your type definitions in this file until you create one for the typings registry see typings/registry

Frequently asked questions

  • What's the current browser support for Angular 2 Beta?

  • Why is my service, aka provider, is not injecting parameter correctly?

    • Please use @Injectable() for your service for typescript to correctly attach the metadata (this is a TypeScript problem)
  • How do I run protractor with node 0.12.x?

    • please check out this repo to use the old version of protractor #146
  • Where do I write my tests?

  • How do I start the app when I get EACCES and EADDRINUSE errors?

    • The EADDRINUSE error means the port 8080 is currently being used and EACCES is lack of permission for webpack to build files to ./dist/
  • How to use sass for css?

  • How do I test a Service?

  • How do I add vscode-chrome-debug support?

  • How do I make the repo work in a virtual machine?

  • What are the naming conventions for Angular 2?

  • How do I include bootstrap or jQuery?

  • I'm getting an error about not finding my module that I installed?

  • How do I async load a component?

    • { path: '/about', loader: () => require('es6-promise!./about/about')('About') }
    • Also see es6-promise-loader


AngularClass for their Angular 2 Webpack repo which served as a starting point for the front-end

Support, Questions, or Feedback

Contact us anytime for anything about this repo, Angular 2, or MEAN stack development in general.

enjoy -- Da5id

Looking for corporate Angular/MEAN training, want to host us, or Angular/MEAN consulting? david.r.niciforovic@gmail.com