The popular MEAN Stack is now much more powerful with the Upgraded Angular 4. With the superb performance of NodeJS at the Backend and Angular 4 at the Frontend and MongoDB as the Database — The Combination is too powerful to beat.

We are going to make an MEAN App with Angular 4. The App is going to be a very simple Todo App. The first part is about developing the NodeJS Bakcend, The second Part will contain the Angular App.

Also from the get go we are going to use some good practices like using controllers, services to discipline our code instead of mashing all of them together.

This is the part 2 of the Tutorial — MEAN App Tutorial with Angular 4(Part 2)

And next, This same app will be converted into a Redux version — Getting Started with NgRx

Lets setup the environment

First go here — https://nodejs.org/en/download/ and Install NodeJS. Download and Install MongoDB — https://www.mongodb.com/download-center#community Download a good Text Editor or IDE. I Personally prefer Visual Studio Code — https://code.visualstudio.com/download

Now the environment Setup is done. Let’s get into the command line.

First we need to install ExpressJS. The most popular NodeJS Framework.

npm install -g express express-generator

This will install ExpressJS and the ExpressJS Official generator packages. Now let’s generate the Application using the Express Generator.

express --view=ejs todoapp

Now the express App is generated. Go inside the directory.

cd todoapp

npm install

All the necessary packages will be installed.

At first let’s install all the necessary packages we will be using throughout this app.

npm install --save bluebird mongoose mongoose-paginate nodemon

Our current directory structure is —

/routes /bin /public /node_modules /views app.js package.json package-lock.json

Edit the Package.json files start script from node to nodemon.

Another important point — We won’t be using callbacks, We even won’t be using traditional Promises. We are going to use the great async-await feature introduced in NodeJS 7.6.

Anatomy of an Async Function