Gonzalo Barba Lopez

Software Developer

Read this first

#3 Learning ES6 - Variables (let)

In this post we are going to see how the variables works in ES6


let allows you to declare variables that are limited in scope to the block, statement, or expression on which it is used. This is unlike the var keyword, which defines a variable globally, or locally to an entire function regardless of block scope.

 Block scope

First let see how works the variables in ES5

var message = 'hello';
  var message = 'bye';
console.log(message);  // output: bye

In the case above the variable message is the same in both cases, so is reassigned in the second message(var message = 'bye').

Now let see what happens when we add the second message inside a function.

var message = 'hello';

function test(){
  var message = 'bye';
console.log(message);  // output: hello;

It does not have any impact because is inside the function.
Let see what happens in ES6

let message =

Continue reading →

#2 Learning ES6 - Modules


The name parameter is the name of the object that will receive the exported members. The member parameters specify individual members, while the name parameter imports all of them. name may also be a function if the module exports a single default parameter rather than a series of members. Below are examples.


Let’s do something easy. Below you can see a simple SayHello function:

function SayHello(name){
  return 'Hello ' + name;
console.log('result: ', SayHello('Gonzalo'));

 1 Move the function to a new module

Now we are going to move the function to a new file, for example to welcome.js

function SayHello(name){
  return 'Hello ' + name;

//We need a way to export the module.
export { SayHellon }; 

Now in our main js file, we have to import the new module from welcome.js

import { SayHello } from './welcome';

console.log('result: ',

Continue reading →

#1 Learning ES6 - Const-Declarations

 ES6 Introduction

ECMAScript 6 is the newest version of the ECMAScript standard. This standard was ratified in June 2015. ES2015 is a significant update to the language, and the first major update to the language since ES5 was standardized in 2009. Implementation of these features in major JavaScript engines is underway now.

 Const Declarations

This declaration creates a constant that can be global or local to the function in which it is declared. Constants are block-scoped. The value of a constant cannot change through re-assignment, and a constant cannot be re-declared. An initializer for a constant is required. A constant cannot share its name with a function or a variable in the same scope.

Let’s do some code:

Note: Constants can be declared with uppercase or lowercase, but just by convention, we are using uppercase.

Basic example:

const MY_VAL = 2;
console.log('value: ' +

Continue reading →

Why ReactJS & AngularJs


ReactJS is an open source javascript library provided by Facebook (it’s not a framework), it’s focus on the visualization (Components), as they say many people choose to think of React as the V in MVC.

They built React to solve one problem: building large applications with data that changes over time.

ReactJs provide you a really good benefits for the modularity, performance and make you easy plan and develop a complex apps making easy work with data and events.


AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML’s syntax to express your application’s components clearly and succinctly. Angular’s data binding and dependency injection eliminate much of the code you would otherwise have to write. And it all happens within the browser, making it an ideal partner with any server

Continue reading →

A Good or Bad practice - How you don’t have to set the config of an environment?

In the last 5 years that I have worked as developer, I saw a lot of times developers often use a switch to set the path (both in back-end and front-end).
Take a look below to see what I mean:

 Back-end example (c#):

 public static string getHost(EnvironmentEnum environment){
            var path = String.Empty
            switch (environment)
                case EnvironmentEnum.dev:
                    path = "http://localhost:55793/";
                case EnvironmentEnum.uat:
                    path = "http://dev.yourpath.com/";
                case EnvironmentEnum.production:
                    path = "http://yourpath.com/";
            return path;

 Front-end example (javascript):

(function () {
    if (window.location.host.indexOf("localhost") !== -1) {

Continue reading →

How to access to a website(c#) from a class library and avoid .NET login

I spent a couple of days trying to access to my web application which has a .NET login implemented.

Basically what I did is request the login and find the value of the session I need to keep the session open and then request actions later.

Below you can see the function I have implemented to get the cookie.


public Cookie GetAuthCookie(string email, string password)
    var postData =  String.Format("Email={0}&Password={1}", email, password);
    var request = (HttpWebRequest)HttpWebRequest.Create(_path);
    request.AllowAutoRedirect = false;
    //Proxy credentials
    var proxy = WebRequest.DefaultWebProxy;
    if (proxy != null)
       request.Proxy = proxy;
       request.Credentials =   CredentialCache.DefaultNetworkCredentials;
       request.Proxy.Credentials =                       CredentialCache.DefaultNetworkCredentials;
    request.Method =

Continue reading →

Quick guide - Adding an existing project to GitHub

  1. Create a new repository by the website.
  2. Using the terminal go to your local project.
  3. Initialize the local directory as a Git repository.
    $ git init
  4. Add the files in your new local repository.
    $ git add .
  5. Commit the files that you’ve staged in your local repository.
    $ git commit -m 'First commit'
  6. Copy the remote repository URL(“https”) ¦¦ get this in https://github.com/yourusername/yourproject.
  7. Add the URL for the remote repository where your local repository will be pushed.
    $ git remote add origin remote repository URL
    $ git remote -v
  8. Push the changes in your local repository to GitHub.
    $ git push origin master

source: help.github

Continue reading →

Getting Started with Sailsjs

Sails.js make it easy to build custom, enterprise-grade Node.js apps. It is designed to mimic the MVC pattern of frameworks like Ruby on Rails, but with support for the requirements of modern apps: data-driven APIs with scalable, service-oriented architecture


To install the latest stable release with the command-line tool:

sudo npm -g install sails

Create a new app:

sails new newProject

Now lift the server:

  $ cd newProject
  $ sails lift

you will see the default home page http://localhost:1337/

 Assets Folder

Assets refer to anything (js, css, html, images, etc) that needs to be accessible to the outside world. The assets folder is where all of your assets will go, and will be served as static assets


Sails allows the developer to change the way Sails configures the created app to fit the project’s needs


There are three kinds of views in Sails

Continue reading →

Getting started with GIT

Git allows groups of people to work on the same documents (often code) at the same time, and without stepping on each other’s toes. It’s a distributed version control system.

First you have to install git in your computer. You can follow the steps in github website.

  • Download and Install Git

 Initialize a Git

To initialize a Git repository here, type the following command:

 $ git init

 Check current state of our project

Command to see what the current state of our project is:

    $ git status

After any change you should run the git status command again to see how the repository status has changed.

 Add & track changes

To tell Git to start tracking changes made to myFile.txt. we first need to add it to the staging area by using git add

    $ git add myFile.txt

Git is now tracking our myFile.txt file. Let’s run git status again to see where we stand

 Store our

Continue reading →

How to create a REST API using Node.js, express and mongodb

Here is a guide showing how to build an API using Node.js, Express, and MongoDB.

 What do we need?

  • Install node.js.
  • Install Mongo DB mongodb

There are different solutions installing the MongoDB Driver for Node.js ( ex. Mongoose and Mongolia)

 Getting started

  1. Create a folder named nodegames anywhere on your file system
  2. In the nodegames folder, create a file named app.js.

 Installing Express

Express is a minimal and flexible node.js web application framework, providing a robust set of features for building single and multi-page, and hybrid web applications.
With a myriad of HTTP utility methods and Connect middleware at your disposal, creating a robust user-friendly API is quick and easy.

To install Express in our application:

  • In the nodegames folder, create a file named package.json defined as follows
            "name": "game-repository"
            "description": "Game

Continue reading →