Tech Junkie Blog - Real World Tutorials, Happy Coding!: March 2017

Thursday, March 30, 2017

In our AngularJS SPA application we will be using the Express web server to serve up our web application.  In the previous blog post we installed the Express-generator globally.  Now we can install Express in the root folder of our SPA application.

Here are the steps to create an Express application:

1.  Open the command line prompt at the root folder of the SPA application

Wednesday, March 29, 2017

Logging is a good service to add as the application gets more complicated.  It will allow us to see what the error is when things goes wrong.

To add logging to our ASP.NET Core application follow the steps below:

1.  Open the Startup.cs file and add the logging service to the ConfigureServices method with the line

services.AddLogging();

So your ConfigureServices method should look like the following


        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            var connectionString = Startup.Configuration["Data:NorthwindContextConnection"];
            services.AddDbContext(options => options.UseSqlServer(connectionString));

            services.AddLogging();
        }


Thursday, March 23, 2017

In order to install the Express web server on the fly on your machine you need to install the Express generator.  Fortunately with NodeJS it is as easy as typing in a command in the command line.  This step used to install Express globally so that it will be easy for development.

Here are the steps to install Express generator globally:

1.  Open up the command line and type in the following command
     npm install -g express-generator

   

Wednesday, March 22, 2017

In the previous blog we created the NorthwindCafe database with Entity Framework Core.  Now we are going to seed the database so that we can work with the data.

Here are the steps to seed the NorthwindCafe database:

1.  Create a file call DBInitializer in the NorthwindCafe.Web folder, in the file type in the following code


using System.Linq;

namespace NorthwindCafe.Web.Models
{
    public class DbInitializer
    {
        public static void Initialize(NorthwindContext context)
        {
            context.Database.EnsureCreated();

            if(context.Categories.Any())
            {
                return;
            }

            var categories = new Category[]
            {
               new Category {Name = "Coffee", Description="Coffee", Products = new Product[] { new Product { Name = "Dark Roast", Description = "Dark Roast", Price = 2.0M } } },
               new Category {Name = "Tea", Description="Tea", Products = new Product[] { new Product { Name = "Chai", Description = "Chai", Price = 1.5M } } },
               new Category {Name = "Pastry", Description="Pastry", Products = new Product[] { new Product { Name = "Cupcake", Description = "Cupcake", Price = 1.25M } } },
               new Category {Name = "Food", Description = "Food", Products = new Product[] { new Product  { Name = "Hamburger", Description = "Hamburger", Price = 5.0M } } }
            };

            foreach (var c in categories)
            {
                context.Categories.Add(c);

            }

            context.SaveChanges();
        }
    }
}


Thursday, March 16, 2017

In the previous blog post we created a configuration file for our MongoDB database in this post we will install MongoDB as a Windows service so that we don't have to start the service in the command line every time we want to use it to save development time.

Here are the steps to install MongoDB:

1.  Open the command prompt as an "Administrator"

2.  Change the mongo-db-config.conf file to use absolute paths.  You can get the instructions on how to create a MongoDB configuration file in this blog post

            dbpath = C:\techjunkie\mongodb\db
            logpath = C:\techjunkie\mongodb\mongo-db-server.log
            verbose = vvvvv

if the folder dpath folder does not exists in Windows create the folder "db" inside the "mongodb" folder, else the service start will fail

Thursday, March 9, 2017

In the previous blog post be installed mongoDB now, we are going to create a configuration file for mongoDB to use during startup.

In this configuration file we will specify the following:

  • location of the data files
  • log file path
  • the verbosity of the log file

Here are the steps:

  1. Create a folder in your operating systems
  2. create a file call mongo-db-config.config in the folder
  3. Type in the following lines of configuration settings
            dbpath = /techjunkie/mongodb/db
            logpath = /techjunkie/mongodb/mongo-db-server.log
            verbose = vvvvv
         
           dbpath : specifies the path of the data files
           logpath : specifies the path of the log file
           verbose: specifies how verbose we want out log files to be, in this we want our log files to be very verbose we want to log everything.  The settings is from v to vvvvv  going from least to most verbose

Thursday, March 2, 2017

Now that we have our AngularJS environment set up we need a database.  We are going to use MongoDB as a database.  MongoDB is a NoSQL database which is a perfect fit for JavaScript centric applications that we are building.  To install MongDB go to https://www.mongodb.com/download-center?jmp=nav#community to make sure you are installing the "Community Edition" of MongoDB.  On the "Community Server" tab select the operating system that you will be installing MongoDB in, then click on the "Download button.

Search This Blog