Author Archives: BrunoLM

About BrunoLM

Power NVM – A Node Version Manager for Windows

nvm is a popular tool that runs on bash to manager node versions. power-nvm is a version I created for Windows, to install:

Install-Module -Name power-nvm

It has the following commands (for now):

nvm default <Version>   # set version as default
nvm install <Version>   # install version
nvm ls [Filter]         # list installed versions
nvm ls-remote [Filter]  # list released versions
nvm setdir <Path>       # set NODE main dir
nvm use <Version>       # use NODE version

Continue reading

Blazor: Running C# in Frontend (cross-browser)

Blazor is a framework that allows you to code C# for frontend. Github page.

An experimental web UI framework using C#/Razor and HTML, running client-side via WebAssembly

The arrival of WebAssembly creates the possibility of building client-side web applications using languages and runtimes that are more typically used for native app development. Blazor runs .NET code in the browser via a small, portable .NET runtime called DotNetAnywhere (DNA) compiled to WebAssembly.

The programming model will be familiar to anyone who’s worked with Razor (the C#/HTML page format used by ASP.NET MVC and ASP.NET Pages).

Blazor makes your app compact and much faster since it is compiled into code the browser doesn’t have to parse.

It can run on older browsers (ex IE11) because it has polyfills.

The only note here is that it is very early. I mean, it is so early it can’t even be called alpha or anything. It is just an experiment at the moment. (Post written at 2017-08-12)

Continue reading

How it works: Angular Routes

Angular routes allows you to setup how your components are going to show up in the page.

Routes can be guarded (like require a login to access) and they can be nested (you can have components render components in a specific route).

Routes can also be setup as lazy, they will only load the component when needed. And you can delegate the loading to sub modules.

“Full” setup

You can check a “full” setup in this plnkr example – setting up Angular routes with lazy load and child routes.

The basics

export const routes: Routes = [
  // if it hits root then go to fooroute
  { path: '', redirectTo: 'fooroute', pathMatch: 'full' },

  // if it hits this route then render FooComponent
  { path: 'fooroute', component: FooComponent },

  // if no routes were found falls into this one that renders Notfound
  { path: '**', component: NotfoundComponent },

Route with parameters

You can use :name to declare parameters in your route.

{ path: 'heroes/:id', component: HeroesComponent },

To create links passing parameters you can pass an array with the route and all parameters, like this:

<a [routerLink]="['heroes', 1]">Saitama</a>

To access the parameters you need private route: ActivatedRoute on your constructor to get route information, and you need to implement OnInit and OnDestroy.

import { Component, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

export class HeroesComponent implements OnInit, OnDestroy {
  id: any;
  sub: any;

  constructor(private route: ActivatedRoute) {

  ngOnInit() {
    this.sub = this.route.params.subscribe((params) => { = +params['id'];

  ngOnDestroy() {

Route with guard

A guard is a class that implements CanActivate or CanActivateChild. In a single route (as the examples above) you might want to use CanActivate, but when you have child routes you might want to use CanActivateChild (for example in /admin routes protecting everything inside it).

Both interfaces are do the samething, they have a method that returns true or false and can redirect you to another page (ex: login page).

An example that could be used to protect an admin area, only allow access if the user is logged in.

import { CanActivateChild, Router } from '@angular/router';

import { Injectable } from '@angular/core';

export class AuthGuard implements CanActivateChild {
  constructor(private router: Router) { }

  canActivateChild() {
    if (localStorage.getItem('user')) {
      return true;

    return false;

Route with lazy and children

import { RouterModule, Routes } from '@angular/router';

import { AuthGuard } from 'src/auth.guard'; // see previous example
import { ModuleWithProviders } from '@angular/core';

import { InternalComponent } from 'src/layouts/internal.component';
import { PublicComponent } from 'src/layouts/public.component';

export const routes: Routes = [
  { path: '', redirectTo: 'heroes', pathMatch: 'full' },

    path: '',
    canActivateChild: [AuthGuard], // protects all heroes routes
    component: InternalComponent,
    children: [
      { path: 'heroes', loadChildren: 'src/heroes/heroes.module#HeroesModule' },

    path: '',
    component: PublicComponent,
    children: [
      { path: 'login', loadChildren: 'src/login/login.module#LoginModule' },
      // { path: 'error', loadChildren: 'src/error/error.module#ErrorModule' },

  // { path: '**', redirectTo: 'error' },

export const router: ModuleWithProviders = RouterModule.forRoot(routes);

Module setup

In app.module

  imports: [ RouterModule.forRoot(routes) ],

In sub modules (if lazy loading)

  imports: [ RouterModule.forChild(routes) ],

If I’m missing a piece of configuration here, then check the plnkr example – setting up Angular routes with lazy load and child routes which is working and you can complete the error route for practice. 🙂

How it works: Angular Tests

Angular tests are always in the same place as the code. When you create a component, service, pipe, directive with ng generate it will always also generate a .spec.ts file.

Every file with the extension .spec.ts is a test file that is caught by the testing tool. Each thing is tested in a different way. For a really long documentation on tests check the official documentation here.

Continue reading

How it works: Angular Pipes

Angular pipes are functions that transform values. There are some built-in pipes and you can create your own pipes.

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({ name: 'required' })
export class RequiredPipe implements PipeTransform {
  transform(value: string, ...args: any[]) {
    return `The field ${value} is required.`;

Continue reading